<?php
session_start(); // Initialize session data
ob_start(); // Turn on output buffering
?>
<?php include "ewcfg6.php" ?>
<?php include "ewmysql6.php" ?>
<?php include "phpfn6.php" ?>
<?php include "solicitudes_onlineinfo.php" ?>
<?php include "usuarioinfo.php" ?>
<?php include "userfn6.php" ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // Always modified
header("Cache-Control: private, no-store, no-cache, must-revalidate"); // HTTP/1.1 
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php

// Define page object
$solicitudes_online_delete = new csolicitudes_online_delete();
$Page =& $solicitudes_online_delete;

// Page init processing
$solicitudes_online_delete->Page_Init();

// Page main processing
$solicitudes_online_delete->Page_Main();
?>
<?php include "header.php" ?>
<script type="text/javascript">
<!--

// Create page object
var solicitudes_online_delete = new ew_Page("solicitudes_online_delete");

// page properties
solicitudes_online_delete.PageID = "delete"; // page ID
var EW_PAGE_ID = solicitudes_online_delete.PageID; // for backward compatibility

// extend page with Form_CustomValidate function
solicitudes_online_delete.Form_CustomValidate = 
 function(fobj) { // DO NOT CHANGE THIS LINE!

 	// Your custom validation code here, return false if invalid. 
 	return true;
 }
<?php if (EW_CLIENT_VALIDATE) { ?>
solicitudes_online_delete.ValidateRequired = true; // uses JavaScript validation
<?php } else { ?>
solicitudes_online_delete.ValidateRequired = false; // no JavaScript validation
<?php } ?>

//-->
</script>
<script language="JavaScript" type="text/javascript">
<!--

// Write your client script here, no need to add script tags.
// To include another .js script, use:
// ew_ClientScriptInclude("my_javascript.js"); 
//-->

</script>
<?php

// Load records for display
$rs = $solicitudes_online_delete->LoadRecordset();
$solicitudes_online_deletelTotalRecs = $rs->RecordCount(); // Get record count
if ($solicitudes_online_deletelTotalRecs <= 0) { // No record found, exit
	$rs->Close();
	$solicitudes_online_delete->Page_Terminate("solicitudes_onlinelist.php"); // Return to list
}
?>
<p><span class="phpmaker">Borrar de TABLA: solicitudes online<br><br>
<a href="<?php echo $solicitudes_online->getReturnUrl() ?>">Regresar</a></span></p>
<?php $solicitudes_online_delete->ShowMessage() ?>
<form action="<?php echo ew_CurrentPage() ?>" method="post">
<p>
<input type="hidden" name="t" id="t" value="solicitudes_online">
<input type="hidden" name="a_delete" id="a_delete" value="D">
<?php foreach ($solicitudes_online_delete->arRecKeys as $key) { ?>
<input type="hidden" name="key_m[]" id="key_m[]" value="<?php echo ew_HtmlEncode($key) ?>">
<?php } ?>
<table class="ewGrid"><tr><td class="ewGridContent">
<div class="ewGridMiddlePanel">
<table cellspacing="0" class="ewTable ewTableSeparate">
<?php echo $solicitudes_online->TableCustomInnerHtml ?>
	<thead>
	<tr class="ewTableHeader">
		<td valign="top">id</td>
		<td valign="top">empresa</td>
		<td valign="top">contacto</td>
		<td valign="top">email</td>
		<td valign="top">tipo</td>
		<td valign="top">fecha registro</td>
	</tr>
	</thead>
	<tbody>
<?php
$solicitudes_online_delete->lRecCnt = 0;
$i = 0;
while (!$rs->EOF) {
	$solicitudes_online_delete->lRecCnt++;

	// Set row properties
	$solicitudes_online->CssClass = "";
	$solicitudes_online->CssStyle = "";
	$solicitudes_online->RowType = EW_ROWTYPE_VIEW; // View

	// Get the field contents
	$solicitudes_online_delete->LoadRowValues($rs);

	// Render row
	$solicitudes_online_delete->RenderRow();
?>
	<tr<?php echo $solicitudes_online->RowAttributes() ?>>
		<td<?php echo $solicitudes_online->id->CellAttributes() ?>>
<div<?php echo $solicitudes_online->id->ViewAttributes() ?>><?php echo $solicitudes_online->id->ListViewValue() ?></div></td>
		<td<?php echo $solicitudes_online->empresa->CellAttributes() ?>>
<div<?php echo $solicitudes_online->empresa->ViewAttributes() ?>><?php echo $solicitudes_online->empresa->ListViewValue() ?></div></td>
		<td<?php echo $solicitudes_online->contacto->CellAttributes() ?>>
<div<?php echo $solicitudes_online->contacto->ViewAttributes() ?>><?php echo $solicitudes_online->contacto->ListViewValue() ?></div></td>
		<td<?php echo $solicitudes_online->email->CellAttributes() ?>>
<div<?php echo $solicitudes_online->email->ViewAttributes() ?>><?php echo $solicitudes_online->email->ListViewValue() ?></div></td>
		<td<?php echo $solicitudes_online->tipo->CellAttributes() ?>>
<div<?php echo $solicitudes_online->tipo->ViewAttributes() ?>><?php echo $solicitudes_online->tipo->ListViewValue() ?></div></td>
		<td<?php echo $solicitudes_online->fecha_registro->CellAttributes() ?>>
<div<?php echo $solicitudes_online->fecha_registro->ViewAttributes() ?>><?php echo $solicitudes_online->fecha_registro->ListViewValue() ?></div></td>
	</tr>
<?php
	$rs->MoveNext();
}
$rs->Close();
?>
</tbody>
</table>
</div>
</td></tr></table>
<p>
<input type="submit" name="Action" id="Action" value="Confirmar Borrado">
</form>
<script language="JavaScript" type="text/javascript">
<!--

// Write your table-specific startup script here
// document.write("page loaded");
//-->

</script>
<?php include "footer.php" ?>
<?php

//
// Page Class
//
class csolicitudes_online_delete {

	// Page ID
	var $PageID = 'delete';

	// Table Name
	var $TableName = 'solicitudes_online';

	// Page Object Name
	var $PageObjName = 'solicitudes_online_delete';

	// Page Name
	function PageName() {
		return ew_CurrentPage();
	}

	// Page Url
	function PageUrl() {
		$PageUrl = ew_CurrentPage() . "?";
		global $solicitudes_online;
		if ($solicitudes_online->UseTokenInUrl) $PageUrl .= "t=" . $solicitudes_online->TableVar . "&"; // add page token
		return $PageUrl;
	}

	// Message
	function getMessage() {
		return @$_SESSION[EW_SESSION_MESSAGE];
	}

	function setMessage($v) {
		if (@$_SESSION[EW_SESSION_MESSAGE] <> "") { // Append
			$_SESSION[EW_SESSION_MESSAGE] .= "<br>" . $v;
		} else {
			$_SESSION[EW_SESSION_MESSAGE] = $v;
		}
	}

	// Show Message
	function ShowMessage() {
		if ($this->getMessage() <> "") { // Message in Session, display
			echo "<p><span class=\"ewMessage\">" . $this->getMessage() . "</span></p>";
			$_SESSION[EW_SESSION_MESSAGE] = ""; // Clear message in Session
		}
	}

	// Validate Page request
	function IsPageRequest() {
		global $objForm, $solicitudes_online;
		if ($solicitudes_online->UseTokenInUrl) {

			//IsPageRequest = False
			if ($objForm)
				return ($solicitudes_online->TableVar == $objForm->GetValue("t"));
			if (@$_GET["t"] <> "")
				return ($solicitudes_online->TableVar == $_GET["t"]);
		} else {
			return TRUE;
		}
	}

	//
	//  Class initialize
	//  - init objects
	//  - open connection
	//
	function csolicitudes_online_delete() {
		global $conn;

		// Initialize table object
		$GLOBALS["solicitudes_online"] = new csolicitudes_online();

		// Initialize other table object
		$GLOBALS['usuario'] = new cusuario();

		// Intialize page id (for backward compatibility)
		if (!defined("EW_PAGE_ID"))
			define("EW_PAGE_ID", 'delete', TRUE);

		// Initialize table name (for backward compatibility)
		if (!defined("EW_TABLE_NAME"))
			define("EW_TABLE_NAME", 'solicitudes_online', TRUE);

		// Open connection to the database
		$conn = ew_Connect();
	}

	// 
	//  Page_Init
	//
	function Page_Init() {
		global $gsExport, $gsExportFile, $solicitudes_online;
		global $Security;
		$Security = new cAdvancedSecurity();
		if (!$Security->IsLoggedIn()) $Security->AutoLogin();
		if (!$Security->IsLoggedIn()) {
			$Security->SaveLastUrl();
			$this->Page_Terminate("login.php");
		}

		// Global page loading event (in userfn6.php)
		Page_Loading();

		// Page load event, used in current page
		$this->Page_Load();
	}

	//
	//  Page_Terminate
	//  - called when exit page
	//  - if URL specified, redirect to the URL
	//
	function Page_Terminate($url = "") {
		global $conn;

		// Page unload event, used in current page
		$this->Page_Unload();

		// Global page unloaded event (in userfn*.php)
		Page_Unloaded();

		 // Close Connection
		$conn->Close();

		// Go to URL if specified
		if ($url <> "") {
			ob_end_clean();
			header("Location: $url");
		}
		exit();
	}
	var $lTotalRecs;
	var $lRecCnt;
	var $arRecKeys = array();

	// Page main processing
	function Page_Main() {
		global $solicitudes_online;

		// Load Key Parameters
		$sKey = "";
		$bSingleDelete = TRUE; // Initialize as single delete
		$nKeySelected = 0; // Initialize selected key count
		$sFilter = "";
		if (@$_GET["id"] <> "") {
			$solicitudes_online->id->setQueryStringValue($_GET["id"]);
			if (!is_numeric($solicitudes_online->id->QueryStringValue))
				$this->Page_Terminate("solicitudes_onlinelist.php"); // Prevent SQL injection, exit
			$sKey .= $solicitudes_online->id->QueryStringValue;
		} else {
			$bSingleDelete = FALSE;
		}
		if ($bSingleDelete) {
			$nKeySelected = 1; // Set up key selected count
			$this->arRecKeys[0] = $sKey;
		} else {
			if (isset($_POST["key_m"])) { // Key in form
				$nKeySelected = count($_POST["key_m"]); // Set up key selected count
				$this->arRecKeys = ew_StripSlashes($_POST["key_m"]);
			}
		}
		if ($nKeySelected <= 0)
			$this->Page_Terminate("solicitudes_onlinelist.php"); // No key specified, return to list

		// Build filter
		foreach ($this->arRecKeys as $sKey) {
			$sFilter .= "(";

			// Set up key field
			$sKeyFld = $sKey;
			if (!is_numeric($sKeyFld))
				$this->Page_Terminate("solicitudes_onlinelist.php"); // Prevent SQL injection, return to list
			$sFilter .= "`id`=" . ew_AdjustSql($sKeyFld) . " AND ";
			if (substr($sFilter, -5) == " AND ") $sFilter = substr($sFilter, 0, strlen($sFilter)-5) . ") OR ";
		}
		if (substr($sFilter, -4) == " OR ") $sFilter = substr($sFilter, 0, strlen($sFilter)-4);

		// Set up filter (SQL WhHERE clause) and get return SQL
		// SQL constructor in SQL constructor in solicitudes_online class, solicitudes_onlineinfo.php

		$solicitudes_online->CurrentFilter = $sFilter;

		// Get action
		if (@$_POST["a_delete"] <> "") {
			$solicitudes_online->CurrentAction = $_POST["a_delete"];
		} else {
			$solicitudes_online->CurrentAction = "I"; // Display record
		}
		switch ($solicitudes_online->CurrentAction) {
			case "D": // Delete
				$solicitudes_online->SendEmail = TRUE; // Send email on delete success
				if ($this->DeleteRows()) { // delete rows
					$this->setMessage("Borrado con exito"); // Set up success message
					$this->Page_Terminate($solicitudes_online->getReturnUrl()); // Return to caller
				}
		}
	}

	//
	//  Function DeleteRows
	//  - Delete Records based on current filter
	//
	function DeleteRows() {
		global $conn, $Security, $solicitudes_online;
		$DeleteRows = TRUE;
		$sWrkFilter = $solicitudes_online->CurrentFilter;

		// Set up filter (Sql Where Clause) and get Return SQL
		// SQL constructor in solicitudes_online class, solicitudes_onlineinfo.php

		$solicitudes_online->CurrentFilter = $sWrkFilter;
		$sSql = $solicitudes_online->SQL();
		$conn->raiseErrorFn = 'ew_ErrorFn';
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';
		if ($rs === FALSE) {
			return FALSE;
		} elseif ($rs->EOF) {
			$this->setMessage("No se encontraron registros"); // No record found
			$rs->Close();
			return FALSE;
		}
		$conn->BeginTrans();

		// Clone old rows
		$rsold = ($rs) ? $rs->GetRows() : array();
		if ($rs) $rs->Close();

		// Call row deleting event
		if ($DeleteRows) {
			foreach ($rsold as $row) {
				$DeleteRows = $solicitudes_online->Row_Deleting($row);
				if (!$DeleteRows) break;
			}
		}
		if ($DeleteRows) {
			$sKey = "";
			foreach ($rsold as $row) {
				$sThisKey = "";
				if ($sThisKey <> "") $sThisKey .= EW_COMPOSITE_KEY_SEPARATOR;
				$sThisKey .= $row['id'];
				$conn->raiseErrorFn = 'ew_ErrorFn';
				$DeleteRows = $conn->Execute($solicitudes_online->DeleteSQL($row)); // Delete
				$conn->raiseErrorFn = '';
				if ($DeleteRows === FALSE)
					break;
				if ($sKey <> "") $sKey .= ", ";
				$sKey .= $sThisKey;
			}
		} else {

			// Set up error message
			if ($solicitudes_online->CancelMessage <> "") {
				$this->setMessage($solicitudes_online->CancelMessage);
				$solicitudes_online->CancelMessage = "";
			} else {
				$this->setMessage("Borrar cancelado");
			}
		}
		if ($DeleteRows) {
			$conn->CommitTrans(); // Commit the changes
		} else {
			$conn->RollbackTrans(); // Rollback changes
		}

		// Call recordset deleted event
		if ($DeleteRows) {
			foreach ($rsold as $row) {
				$solicitudes_online->Row_Deleted($row);
			}	
		}
		return $DeleteRows;
	}

	// Load recordset
	function LoadRecordset($offset = -1, $rowcnt = -1) {
		global $conn, $solicitudes_online;

		// Call Recordset Selecting event
		$solicitudes_online->Recordset_Selecting($solicitudes_online->CurrentFilter);

		// Load list page SQL
		$sSql = $solicitudes_online->SelectSQL();
		if ($offset > -1 && $rowcnt > -1) $sSql .= " LIMIT $offset, $rowcnt";

		// Load recordset
		$conn->raiseErrorFn = 'ew_ErrorFn';	
		$rs = $conn->Execute($sSql);
		$conn->raiseErrorFn = '';

		// Call Recordset Selected event
		$solicitudes_online->Recordset_Selected($rs);
		return $rs;
	}

	// Load row based on key values
	function LoadRow() {
		global $conn, $Security, $solicitudes_online;
		$sFilter = $solicitudes_online->KeyFilter();

		// Call Row Selecting event
		$solicitudes_online->Row_Selecting($sFilter);

		// Load sql based on filter
		$solicitudes_online->CurrentFilter = $sFilter;
		$sSql = $solicitudes_online->SQL();
		if ($rs = $conn->Execute($sSql)) {
			if ($rs->EOF) {
				$LoadRow = FALSE;
			} else {
				$LoadRow = TRUE;
				$rs->MoveFirst();
				$this->LoadRowValues($rs); // Load row values

				// Call Row Selected event
				$solicitudes_online->Row_Selected($rs);
			}
			$rs->Close();
		} else {
			$LoadRow = FALSE;
		}
		return $LoadRow;
	}

	// Load row values from recordset
	function LoadRowValues(&$rs) {
		global $solicitudes_online;
		$solicitudes_online->id->setDbValue($rs->fields('id'));
		$solicitudes_online->empresa->setDbValue($rs->fields('empresa'));
		$solicitudes_online->contacto->setDbValue($rs->fields('contacto'));
		$solicitudes_online->email->setDbValue($rs->fields('email'));
		$solicitudes_online->telefono->setDbValue($rs->fields('telefono'));
		$solicitudes_online->mensaje->setDbValue($rs->fields('mensaje'));
		$solicitudes_online->tipo->setDbValue($rs->fields('tipo'));
		$solicitudes_online->cod_usuario->setDbValue($rs->fields('cod_usuario'));
		$solicitudes_online->atendido->setDbValue($rs->fields('atendido'));
		$solicitudes_online->fecha_registro->setDbValue($rs->fields('fecha_registro'));
	}

	// Render row values based on field settings
	function RenderRow() {
		global $conn, $Security, $solicitudes_online;

		// Call Row_Rendering event
		$solicitudes_online->Row_Rendering();

		// Common render codes for all row types
		// id

		$solicitudes_online->id->CellCssStyle = "";
		$solicitudes_online->id->CellCssClass = "";

		// empresa
		$solicitudes_online->empresa->CellCssStyle = "";
		$solicitudes_online->empresa->CellCssClass = "";

		// contacto
		$solicitudes_online->contacto->CellCssStyle = "";
		$solicitudes_online->contacto->CellCssClass = "";

		// email
		$solicitudes_online->email->CellCssStyle = "";
		$solicitudes_online->email->CellCssClass = "";

		// tipo
		$solicitudes_online->tipo->CellCssStyle = "";
		$solicitudes_online->tipo->CellCssClass = "";

		// fecha_registro
		$solicitudes_online->fecha_registro->CellCssStyle = "";
		$solicitudes_online->fecha_registro->CellCssClass = "";
		if ($solicitudes_online->RowType == EW_ROWTYPE_VIEW) { // View row

			// id
			$solicitudes_online->id->ViewValue = $solicitudes_online->id->CurrentValue;
			$solicitudes_online->id->CssStyle = "";
			$solicitudes_online->id->CssClass = "";
			$solicitudes_online->id->ViewCustomAttributes = "";

			// empresa
			$solicitudes_online->empresa->ViewValue = $solicitudes_online->empresa->CurrentValue;
			$solicitudes_online->empresa->CssStyle = "";
			$solicitudes_online->empresa->CssClass = "";
			$solicitudes_online->empresa->ViewCustomAttributes = "";

			// contacto
			$solicitudes_online->contacto->ViewValue = $solicitudes_online->contacto->CurrentValue;
			$solicitudes_online->contacto->CssStyle = "";
			$solicitudes_online->contacto->CssClass = "";
			$solicitudes_online->contacto->ViewCustomAttributes = "";

			// email
			$solicitudes_online->email->ViewValue = $solicitudes_online->email->CurrentValue;
			$solicitudes_online->email->CssStyle = "";
			$solicitudes_online->email->CssClass = "";
			$solicitudes_online->email->ViewCustomAttributes = "";

			// tipo
			$solicitudes_online->tipo->ViewValue = $solicitudes_online->tipo->CurrentValue;
			$solicitudes_online->tipo->CssStyle = "";
			$solicitudes_online->tipo->CssClass = "";
			$solicitudes_online->tipo->ViewCustomAttributes = "";

			// fecha_registro
			$solicitudes_online->fecha_registro->ViewValue = $solicitudes_online->fecha_registro->CurrentValue;
			$solicitudes_online->fecha_registro->ViewValue = ew_FormatDateTime($solicitudes_online->fecha_registro->ViewValue, 5);
			$solicitudes_online->fecha_registro->CssStyle = "";
			$solicitudes_online->fecha_registro->CssClass = "";
			$solicitudes_online->fecha_registro->ViewCustomAttributes = "";

			// id
			$solicitudes_online->id->HrefValue = "";

			// empresa
			$solicitudes_online->empresa->HrefValue = "";

			// contacto
			$solicitudes_online->contacto->HrefValue = "";

			// email
			$solicitudes_online->email->HrefValue = "";

			// tipo
			$solicitudes_online->tipo->HrefValue = "";

			// fecha_registro
			$solicitudes_online->fecha_registro->HrefValue = "";
		}

		// Call Row Rendered event
		$solicitudes_online->Row_Rendered();
	}

	// Page Load event
	function Page_Load() {

		//echo "Page Load";
	}

	// Page Unload event
	function Page_Unload() {

		//echo "Page Unload";
	}
}
?>
