name = "Besucher"; $this->filterProperty = "name"; $this->sortProperty = "name"; $this->sortOrder = "ASC"; $this->filter = ""; $this->allowedProperties = array("name", "address", "email", "events"); $this->propertyLabels = array("Name", "Anschrift", "E-Mail", "Veranstaltungen"); $this->lastExportDate = "0000-00-00"; } /** installs a log table */ //----------------------------------------------- function install(){ //----------------------------------------------- $query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_customerlist ( exportDate DATETIME, data VARCHAR(32), PRIMARY KEY (exportDate) )"); dbQuery($query); } /** @see CmsObject::load() */ //----------------------------------------------- function load($path=array()){ //----------------------------------------------- $query = sprintf("SELECT MAX(exportDate) FROM bruckm_customerlist"); $result = dbQuery($query); if($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){ $this->lastExportDate = $line['MAX(exportDate)']; } } /** @see CmsObject::update() */ //----------------------------------------------- function update(){ //----------------------------------------------- $this->sortProperty = $_POST['sortProperty']; $this->sortOrder = $_POST['sortOrder']; $this->filterProperty = $_POST['filterProperty']; $this->filter = $_POST['filter']; } /** @see CmsObject::printContent() */ //----------------------------------------------- function printContent(){ //----------------------------------------------- $out = $this->doPrintMetadata(); $out .= $this->doPrintErrors(); $out .= $this->doPrintCustomerList(); return $out; } /** @see CmsObject:doPrintMetadata() */ //----------------------------------------------- function doPrintMetadata(){ //----------------------------------------------- $t = new Template(CMS_TEMPLATE_DIR."customerlist1.html"); $t->setVar("NAME", htmlspecialchars($this->name)); //sort properties $p = ""; foreach($this->allowedProperties as $i=>$prop){ if($prop == $this->sortProperty){ $p .= ""; } $t->setVar("SORT_PROPERTIES", $p); if($this->sortOrder == "ASC"){ $t->setVar("ORDER_ASC", "selected=\"selected\""); $t->setVar("ORDER_DESC", ""); } else{ $t->setVar("ORDER_DESC", "selected=\"selected\""); $t->setVar("ORDER_ASC", ""); } //filter properties $p = ""; foreach($this->allowedProperties as $i=>$prop){ if($prop == $this->filterProperty){ $p .= ""; } $t->setVar("FILTER_PROPERTIES", $p); $t->setVar("FILTER", $this->filter); return $t->toString(); } /** lists all customers, sorted & filtered */ //---------------------------------------------- function doPrintCustomerList(){ //---------------------------------------------- $result = $this->doLoadCustomers(); $email = array(); $list = ""; while($customer = mysqli_fetch_array($result, MYSQLI_ASSOC)){ if(!empty($customer['email']) && !in_array($customer['email'], $email)){ $email[] = $customer['email']; $id = $customer['id']; $c = ""; $c .= "
".htmlspecialchars($customer['surname']." ".$customer['firstname'])." $customer[acad]
"; $c .= "
$customer[email] $customer[phone]
"; $c .= "
".htmlspecialchars($customer['zip']." ".$customer['city'])." ".htmlspecialchars($customer['address'])."
"; $c .= "
".htmlspecialchars($customer['events'])."
"; $c .= "
\"Besucher
"; $c .= "\n"; $list .= $c; } } $t = new Template(CMS_TEMPLATE_DIR."customerlist2.html"); $t->setVar("CUSTOMERS", $list); $t->setVar("COUNT", mysql_num_rows($result)); return $t->toString(); } /** @see CmsObject::handleAction() */ //--------------------------------------------- function handleAction($action, $position=0, $type=NULL){ //--------------------------------------------- switch($action){ case "download_complete_all": $this->doUpdateExportDate("complete only (all)"); $this->doDownload("complete only", false); break; case "download_complete_new": $this->doUpdateExportDate("complete only (new)"); $this->doDownload("complete only", true); break; case "download_all": $this->doUpdateExportDate("all (all)"); $this->doDownload("all", false); break; case "deleteCustomer": $this->doDeleteCustomer($position); break; } } /** @see CmsObject::getCssClass() */ //----------------------------------------------- function getCssClass(){ //----------------------------------------------- return "itemCustomers"; } // === ADDITIONAL METHODS ================================================================= // /** offers an exported csv file for download * @param data type of download data * @param new true, if only newly added data (since last download) * @warning: EXITS THE PHP SCRIPT! */ //----------------------------------------------- function doDownload($data, $new){ //----------------------------------------------- //download only customers with complete address data if($data == "complete only"){ $customers = ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; if($new){ $query = sprintf("SELECT * FROM bruckm_ticketcustomer WHERE creationDate > %s AND surname != '' AND firstname != '' AND address != '' AND zip != NULL AND city != '' ORDER BY surname ASC, firstname ASC", sqlstring($this->lastExportDate)); } else{ $query = sprintf("SELECT * FROM bruckm_ticketcustomer WHERE surname != '' AND firstname != '' AND address != '' AND zip IS NOT NULL AND city != '' ORDER BY surname ASC, firstname ASC"); } $result = dbQuery($query); while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){ $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; } $customers .= "
VornameNachnameAdressePLZOrt
$line[firstname]$line[surname]$line[address]$line[zip]$line[city]
"; } //download complete customer list else{ $genres = array(); $customers = ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; //load genres $query = sprintf("SELECT id,name FROM bruckm_index WHERE class = 'TicketGenre' ORDER BY name ASC"); $result = dbQuery($query); while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){ $genres[] = $line['id']; $customers .= ""; } $customers .= ""; //load customers $query = sprintf("SELECT * FROM bruckm_ticketcustomer ORDER BY surname ASC, firstname ASC"); $result = dbQuery($query); while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){ $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $customers .= ""; $cGenres = array_count_values(explode(",", $line['genres'])); foreach($genres as $g){ $customers .= ""; } $customers .= ""; } $customers .= "
NachnameVornameAdressePLZOrtE-MailTelefon$line[name]
$line[surname]$line[firstname]$line[address]$line[zip]$line[city]$line[email]$line[phone]$cGenres[$g]
"; } header("Content-Type: application/vnd-ms-excel"); header("Content-Disposition: attachment; filename=\"export.xls\""); header('Pragma: no-cache'); header('Expires: 0'); echo $customers; exit(); } /** updates the export date * @param data type of download data */ //----------------------------------------------- function doUpdateExportDate($data){ //----------------------------------------------- $query = sprintf("INSERT INTO bruckm_customerlist (exportDate, data) VALUES (NOW(), %s)", sqlstring($data)); dbQuery($query); } /** sets the id * @param id id */ //----------------------------------------------- function setId($id){ //----------------------------------------------- $this->id = $id; } /** loads the list of customers, sorted & filtered * @return db result set */ //----------------------------------------------- function doLoadCustomers(){ //----------------------------------------------- //sorting switch($this->sortProperty){ case "name": $order = "surname ".$this->sortOrder.", firstname ".$this->sortOrder; break; case "address": $order = "zip ".$this->sortOrder.", city ".$this->sortOrder.", address ".$this->sortOrder; break; case "email": $order = "email ".$this->sortOrder; break; case "events": $order = "eventCount ".$this->sortOrder.", events ".$this->sortOrder; break; default: $order = $this->sortProperty." ".$this->sortOrder; } //filter if(!empty($this->filter)){ switch($this->filterProperty){ case "name": $filter = "WHERE surname LIKE '%".$this->filter."%'"; break; case "address": if(is_numeric($this->filter)){ $filter = "WHERE zip = ".$this->filter; } else{ $filter = "WHERE city = '".$this->filter."' || address LIKE '%".$this->filter."%'"; } break; default: $filter = "WHERE ".$this->filterProperty." LIKE '%".$this->filter."%'"; } } //no filter: remove empty values from sorting else{ switch($this->sortProperty){ case "name": $filter = ""; break; case "address": $filter = "WHERE zip != 0 || city != ''"; break; default: $filter = "WHERE ".$this->sortProperty." != ''"; } } $query = sprintf("SELECT * FROM bruckm_ticketcustomer %s ORDER BY %s", $filter, $order); return dbQuery($query); } /** deletes a customer from the list * @param id customer id */ //-------------------------------------------- function doDeleteCustomer($id){ //-------------------------------------------- $query = sprintf("SELECT id FROM bruckm_ticket WHERE customerId = %d LIMIT 1", $id); $result = dbQuery($query); if(mysql_num_rows($result) > 0){ $this->addError("Der Besucher kann nicht gelöscht werden (aktuelle Reservierung)!"); return; } $query = sprintf("DELETE FROM bruckm_ticketcustomer WHERE id = %d", $id); dbQuery($query); } }; ?>