130 lines
3.2 KiB
PHP
130 lines
3.2 KiB
PHP
<?php
|
|
|
|
/** Customer Group Container
|
|
* managed customer groups
|
|
*
|
|
* @version 1.0.0
|
|
* @since 2008-09-07
|
|
*
|
|
*/
|
|
class CustomerGroupContainer extends CmsObject{
|
|
|
|
/** C'tor
|
|
*/
|
|
//-----------------------------------------------
|
|
function CustomerGroupContainer($id, $parent){
|
|
//-----------------------------------------------
|
|
parent::CmsObject($id, $parent);
|
|
$this->name = "Besuchergruppen";
|
|
}
|
|
|
|
|
|
/** @see CmsObject::printContent()
|
|
*/
|
|
//-----------------------------------------------
|
|
function printContent(){
|
|
//-----------------------------------------------
|
|
return $this->doPrintGroups();
|
|
}
|
|
|
|
|
|
/** prints the alphabetical index
|
|
*/
|
|
//-----------------------------------------------
|
|
function doPrintGroups(){
|
|
//-----------------------------------------------
|
|
$groups = "";
|
|
$query = sprintf("SELECT * FROM bruckm_ticketcustomergroup ORDER BY name ASC");
|
|
$result = dbQuery($query);
|
|
while ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
|
|
$t = new Template(CMS_TEMPLATE_DIR."customergroup.html");
|
|
$t->setVar("ID", $line['id']);
|
|
$t->setVar("NAME", htmlspecialchars($line['name']));
|
|
$groups .= $t->toString();
|
|
}
|
|
$t = new Template(CMS_TEMPLATE_DIR."customergroup.html");
|
|
$t->setVar("ID", 0);
|
|
$t->setVar("NAME", "");
|
|
$groups .= $t->toString();
|
|
return $groups;
|
|
}
|
|
|
|
|
|
/** @see CmsObject::handleAction()
|
|
*/
|
|
//---------------------------------------------
|
|
function handleAction($action, $position=0, $type=NULL){
|
|
//---------------------------------------------
|
|
switch($action){
|
|
case "saveGroup":
|
|
$this->doSaveGroup($position);
|
|
break;
|
|
case "removeGroup":
|
|
$this->doRemoveGroup($position);
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::getCssClass()
|
|
*/
|
|
//-----------------------------------------------
|
|
function getCssClass(){
|
|
//-----------------------------------------------
|
|
return "itemCustomers";
|
|
}
|
|
|
|
|
|
// === ADDITIONAL METHODS ================================================================= //
|
|
|
|
|
|
/** sets the id
|
|
* @param id id
|
|
*/
|
|
//-----------------------------------------------
|
|
function setId($id){
|
|
//-----------------------------------------------
|
|
$this->id = $id;
|
|
}
|
|
|
|
|
|
|
|
/** updates or inserts a customer group
|
|
* @param id group id (or 0, if a new group is to be created)
|
|
*/
|
|
//-----------------------------------------------
|
|
function doSaveGroup($id){
|
|
//-----------------------------------------------
|
|
$name = $_POST['group' . $id];
|
|
if (!$id) {
|
|
$query = sprintf("INSERT INTO bruckm_ticketcustomergroup (name) VALUES (%s)",
|
|
sqlstring($name));
|
|
dbQuery($query);
|
|
}
|
|
else {
|
|
$query = sprintf("UPDATE bruckm_ticketcustomergroup SET name = %s WHERE id = %d",
|
|
sqlstring($name),
|
|
sqlnum($id));
|
|
dbQuery($query);
|
|
}
|
|
}
|
|
|
|
|
|
/** removes a group and all it's memberships
|
|
*/
|
|
//-----------------------------------------------
|
|
function doRemoveGroup($id){
|
|
//-----------------------------------------------
|
|
if (!$id) {
|
|
return;
|
|
}
|
|
$query = sprintf("DELETE FROM bruckm_ticketcustomergroup WHERE id = %d LIMIT 1", sqlnum($id));
|
|
dbQuery($query);
|
|
$query = sprintf("DELETE FROM bruckm_ticketcustomergroupmemberships WHERE groupId = %d", sqlnum($id));
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
};
|
|
|
|
?>
|