314 lines
9.8 KiB
PHP
314 lines
9.8 KiB
PHP
<?php
|
|
|
|
/** Customer Group List
|
|
* customer list sorted by groups
|
|
*
|
|
* @version 1.0.0
|
|
* @since 2008-09-07
|
|
*
|
|
*/
|
|
class CustomerGroupList extends CmsObject{
|
|
|
|
var $view; // the current view (either list or edit)
|
|
var $group; // the if the selected group (in list view)
|
|
var $customer; // the id of the customer (in edit view)
|
|
|
|
var $VIEW_LIST = "list";
|
|
var $VIEW_EDIT = "edit";
|
|
|
|
/** C'tor
|
|
*/
|
|
//-----------------------------------------------
|
|
function CustomerGroupList($id, $parent){
|
|
//-----------------------------------------------
|
|
parent::CmsObject($id, $parent);
|
|
$this->name = "Besucherliste (Gruppen)";
|
|
$this->group = 0;
|
|
$this->view = $this->VIEW_LIST;
|
|
}
|
|
|
|
|
|
/** @see CmsObject::update()
|
|
*/
|
|
//----------------------------------------------
|
|
function update(){
|
|
//----------------------------------------------
|
|
$this->view = $_POST['currentView'];
|
|
if ($this->view == $this->VIEW_EDIT) {
|
|
$this->customer = $_POST['customerId'];
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::save()
|
|
*/
|
|
//---------------------------------------------
|
|
function save(){
|
|
//---------------------------------------------
|
|
if (!$this->customer) {
|
|
return;
|
|
}
|
|
$query = sprintf("SELECT loose, newsletter FROM bruckm_ticketcustomer WHERE id = %d", sqlnum($this->customer));
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
// update customer data (if registration is loose)
|
|
if ($line['loose'] == 'true') {
|
|
$query = sprintf("UPDATE bruckm_ticketcustomer
|
|
SET firstname = %s, surname = %s, email = %s, acad = %s, address = %s, zip = %d, city = %s, phone = %s, changeDate = NOW()
|
|
WHERE id = %d",
|
|
sqlstring($_POST['firstname']),
|
|
sqlstring($_POST['surname']),
|
|
sqlstring($_POST['email']),
|
|
sqlstring($_POST['acad']),
|
|
sqlstring($_POST['address']),
|
|
sqlnum($_POST['zip']),
|
|
sqlstring($_POST['city']),
|
|
sqlstring($_POST['phone']),
|
|
sqlnum($this->customer));
|
|
dbQuery($query);
|
|
}
|
|
// update newsletter subscription
|
|
if (isset($_POST['newsletter']) && $line['newsletter'] != $_POST['newsletter']) {
|
|
$query = sprintf("UPDATE bruckm_ticketcustomer SET newsletter = %s WHERE id = %d",
|
|
sqlstring($_POST['newsletter']),
|
|
sqlnum($this->customer));
|
|
dbQuery($query);
|
|
}
|
|
// update group memberships
|
|
$query = sprintf("SELECT id FROM bruckm_ticketcustomergroup ORDER BY id ASC");
|
|
$result = dbQuery($query);
|
|
while ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
|
|
if (isset($_POST['groups']) && in_array($line['id'], $_POST['groups'])) {
|
|
$query = sprintf("SELECT * FROM bruckm_ticketcustomergroupmemberships WHERE groupId = %d AND customerId = %d LIMIT 1",
|
|
sqlnum($line['id']),
|
|
sqlnum($this->customer));
|
|
if (mysql_num_rows(dbQuery($query)) == 0) {
|
|
$query = sprintf("INSERT INTO bruckm_ticketcustomergroupmemberships (groupId, customerId) VALUES (%d, %d)",
|
|
sqlnum($line['id']),
|
|
sqlnum($this->customer));
|
|
dbQuery($query);
|
|
}
|
|
}
|
|
else {
|
|
$query = sprintf("DELETE FROM bruckm_ticketcustomergroupmemberships WHERE groupId = %d AND customerId = %d LIMIT 1",
|
|
sqlnum($line['id']),
|
|
sqlnum($this->customer));
|
|
dbQuery($query);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::printContent()
|
|
*/
|
|
//-----------------------------------------------
|
|
function printContent(){
|
|
//-----------------------------------------------
|
|
$out = $this->doPrintGroups();
|
|
if ($this->view == $this->VIEW_LIST) {
|
|
$out .= $this->doPrintList();
|
|
}
|
|
else {
|
|
$out .= $this->doPrintCustomer();
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
|
|
/** prints the alphabetical index
|
|
*/
|
|
//-----------------------------------------------
|
|
function doPrintGroups(){
|
|
//-----------------------------------------------
|
|
$t = new Template(CMS_TEMPLATE_DIR."customerlist4.html");
|
|
$groups = "";
|
|
$query = sprintf("SELECT * FROM bruckm_ticketcustomergroup ORDER BY name ASC");
|
|
$result = dbQuery($query);
|
|
while ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
|
|
$groups .= '<option value="' . $line['id'] . '" ';
|
|
if ($line['id'] == $this->group) {
|
|
$groups .= 'selected="selected"';
|
|
}
|
|
else if (!$this->group) {
|
|
$this->group = $line['id'];
|
|
}
|
|
$groups .= '>' . htmlspecialchars($line['name']) . '</option>';
|
|
}
|
|
$t->setVar("GROUPS", $groups);
|
|
return $t->toString();
|
|
}
|
|
|
|
|
|
/** prints the list view
|
|
*/
|
|
//-----------------------------------------------
|
|
function doPrintList(){
|
|
//-----------------------------------------------
|
|
$t = new Template(CMS_TEMPLATE_DIR."customerlist2.html");
|
|
$query = sprintf("SELECT name FROM bruckm_ticketcustomergroup WHERE id = %d", sqlnum($this->group));
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$t->setVar("TITLE", htmlspecialchars("Gruppe '" . $line['name'] . "'"));
|
|
$results = array();
|
|
$query = sprintf("SELECT customerId FROM bruckm_ticketcustomergroupmemberships WHERE groupId = %d", sqlnum($this->group));
|
|
$result = dbQuery($query);
|
|
while ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
|
|
$query = sprintf("SELECT id, firstname, surname, email FROM bruckm_ticketcustomer WHERE id = %d", sqlnum($line['customerId']));
|
|
$results[] = mysqli_fetch_array(dbQuery($query), MYSQLI_ASSOC);
|
|
}
|
|
$results = $this->sortResults($results);
|
|
$customers = "";
|
|
$i = 0;
|
|
foreach ($results as $line) {
|
|
if ($i++ % 2 == 0) {
|
|
$customers .= '<tr style="background-color:#eeeeee">';
|
|
}
|
|
else {
|
|
$customers .= '<tr>';
|
|
}
|
|
$customers .= '<td><a href="javascript:setAction(\'editCustomer\',' . $line['id'] . ');document.forms[0].submit();" target="_self">»</a></td>';
|
|
$customers .= '<td>' . $line['surname'] . '</td>';
|
|
$customers .= '<td>' . $line['firstname'] . '</td>';
|
|
$customers .= '<td>' . $line['email'] . '</td>';
|
|
$customers .= '</tr>';
|
|
}
|
|
$t->setVar("CUSTOMERS", $customers);
|
|
return $t->toString();
|
|
}
|
|
|
|
|
|
/** prints the edit customer view
|
|
*/
|
|
//-----------------------------------------------
|
|
function doPrintCustomer(){
|
|
//-----------------------------------------------
|
|
$t = new Template(CMS_TEMPLATE_DIR."customerlist3.html");
|
|
$query = sprintf("SELECT * FROM bruckm_ticketcustomer WHERE id = %d", sqlnum($this->customer));
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$t->setVar("ID", $line['id']);
|
|
$t->setVar("FIRSTNAME", $line['firstname']);
|
|
$t->setVar("SURNAME", $line['surname']);
|
|
$t->setVar("EMAIL", $line['email']);
|
|
$t->setVar("ADDRESS", $line['address']);
|
|
$t->setVar("ZIP", $line['zip']);
|
|
$t->setVar("CITY", $line['city']);
|
|
$t->setVar("PHONE", $line['phone']);
|
|
$t->setVar("ACAD", $line['acad']);
|
|
if ($line['loose'] == 'true') {
|
|
$t->setVar("GLOBAL_DISABLE", "");
|
|
}
|
|
else {
|
|
$t->setVar("GLOBAL_DISABLE", "disabled=\"disabled\"");
|
|
}
|
|
if ($line['newsletter'] == 'false') {
|
|
$t->setVar("NEWSLETTER_TRUE", "disabled=\"disabled\"");
|
|
$t->setVar("NEWSLETTER_FALSE", "checked=\"checked\" disabled=\"disabled\"");
|
|
}
|
|
else {
|
|
$t->setVar("NEWSLETTER_TRUE", "checked=\"checked\"");
|
|
$t->setVar("NEWSLETTER_FALSE", "");
|
|
}
|
|
// group memberships
|
|
$groups = "";
|
|
$query = sprintf("SELECT * FROM bruckm_ticketcustomergroup ORDER BY name ASC");
|
|
$result = dbQuery($query);
|
|
while ($group = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
|
|
$query = sprintf("SELECT * FROM bruckm_ticketcustomergroupmemberships WHERE groupId = %d AND customerId = %d LIMIT 1",
|
|
sqlnum($group['id']),
|
|
sqlnum($line['id']));
|
|
if (mysql_num_rows(dbQuery($query)) > 0) {
|
|
$groups .= '<input type="checkbox" name="groups[]" value="' . $group['id'] . '" checked="checked">' . $group['name'] . '<br />';
|
|
}
|
|
else {
|
|
$groups .= '<input type="checkbox" name="groups[]" value="' . $group['id'] . '">' . $group['name'] . '<br />';
|
|
}
|
|
}
|
|
$t->setVar("GROUPS", $groups);
|
|
return $t->toString();
|
|
}
|
|
|
|
|
|
/** @see CmsObject::handleAction()
|
|
*/
|
|
//---------------------------------------------
|
|
function handleAction($action, $position=0, $type=NULL){
|
|
//---------------------------------------------
|
|
switch($action){
|
|
case "showList":
|
|
$this->group = $_POST['group'];
|
|
$this->view = $this->VIEW_LIST;
|
|
break;
|
|
case "editCustomer":
|
|
$this->customer = $position;
|
|
$this->view = $this->VIEW_EDIT;
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::getCssClass()
|
|
*/
|
|
//-----------------------------------------------
|
|
function getCssClass(){
|
|
//-----------------------------------------------
|
|
return "itemCustomers";
|
|
}
|
|
|
|
|
|
// === ADDITIONAL METHODS ================================================================= //
|
|
|
|
|
|
/** sets the id
|
|
* @param id id
|
|
*/
|
|
//-----------------------------------------------
|
|
function setId($id){
|
|
//-----------------------------------------------
|
|
$this->id = $id;
|
|
}
|
|
|
|
|
|
|
|
/** sorts the customers alphabetically
|
|
* @param results list of customers
|
|
* @return sorted list of customers
|
|
*/
|
|
//-----------------------------------------------
|
|
function sortResults($results){
|
|
//-----------------------------------------------
|
|
$size = sizeof($results);
|
|
for ($i = 0; $i < $size; $i++) {
|
|
$min = $this->findMin($results, $i);
|
|
$tmp = $results[$min];
|
|
$results[$min] = $results[$i];
|
|
$results[$i] = $tmp;
|
|
}
|
|
return $results;
|
|
}
|
|
|
|
|
|
/** finds the alphabetically lowest ordered customer
|
|
* @param resulst list of customers
|
|
* @param offset index offset
|
|
* @return index of the lowest ordered customer
|
|
*/
|
|
//-----------------------------------------------
|
|
function findMin($results, $offset){
|
|
//-----------------------------------------------
|
|
$size = sizeof($results);
|
|
$min = strtolower($results[$offset]['surname']);
|
|
$minIndex = $offset;
|
|
for ($i = $offset; $i < $size; $i++) {
|
|
if (strtolower($results[$i]['surname']) < $min) {
|
|
$min = strtolower($results[$i]['surname']);
|
|
$minIndex = $i;
|
|
}
|
|
}
|
|
return $minIndex;
|
|
}
|
|
|
|
|
|
};
|
|
|
|
?>
|