コード例 #1
0
ファイル: events.php プロジェクト: trabisdementia/xuups
<?php

//$Id: events.php,v 1.2 2005/12/02 23:16:09 ackbarr Exp $
if (!defined('XHELP_CLASS_PATH')) {
    exit;
}
//Include the Event Subsystem classes
require_once XHELP_CLASS_PATH . '/eventService.php';
require_once XHELP_CLASS_PATH . '/xhelpService.php';
require_once XHELP_CLASS_PATH . '/cacheService.php';
require_once XHELP_CLASS_PATH . '/logService.php';
require_once XHELP_CLASS_PATH . '/notificationService.php';
require_once XHELP_CLASS_PATH . '/staffService.php';
require_once XHELP_CLASS_PATH . '/firnService.php';
//Create an instance of each event class
$xhelpEventSrv =& xhelpNewEventService();
$var = xhelpCacheService::singleton();
$var = xhelpLogService::singleton();
$var = xhelpNotificationService::singleton();
$var = xhelpStaffService::singleton();
$var = xhelpFirnService::singleton();
unset($var);
// @todo - update every reference to $_eventsrv to use the new $xhelpEventSrv object
$_eventsrv =& $xhelpEventSrv;
コード例 #2
0
ファイル: xhelpService.php プロジェクト: trabisdementia/xuups
 function init()
 {
     $this->_eventSrv =& xhelpNewEventService();
     $this->_attachEvents();
 }
コード例 #3
0
ファイル: fields.php プロジェクト: trabisdementia/xuups
function editField()
{
    global $oAdminButton;
    $eventsrv =& xhelpNewEventService();
    $session =& Session::singleton();
    $regex_array =& _getRegexArray();
    if (!isset($_REQUEST['id'])) {
        redirect_header(xhelpMakeURI(XHELP_ADMIN_URL . '/fields.php', array('op' => 'manageDepartments'), false), 3, _AM_XHELP_MESSAGE_NO_FIELD);
    }
    $fld_id = intval($_REQUEST['id']);
    $hField =& xhelpGetHandler('ticketField');
    if (!($field =& $hField->get($fld_id))) {
        redirect_header(xhelpMakeURI(XHELP_ADMIN_URL . '/fields.php', array('op' => 'manageDepartments'), false), 3, _AM_XHELP_MESSAGE_NO_FIELD);
    }
    if (!isset($_POST['editField'])) {
        //Get Custom Field From session (if exists)
        $field_info = $session->get('xhelp_editField_' . $fld_id);
        $field_errors = $session->get('xhelp_editFieldErrors_' . $fld_id);
        if (!$field_info === false) {
            $fld_controltype = $field_info['controltype'];
            $fld_datatype = $field_info['datatype'];
            $fld_departments = $field_info['departments'];
            $fld_name = $field_info['name'];
            $fld_fieldname = $field_info['fieldname'];
            $fld_description = $field_info['description'];
            $fld_required = $field_info['required'];
            $fld_length = $field_info['length'];
            $fld_weight = $field_info['weight'];
            $fld_defaultvalue = $field_info['defaultvalue'];
            $fld_values = $field_info['values'];
            $fld_validation = $field_info['validation'];
        } else {
            $hFDept =& xhelpGetHandler('ticketFieldDepartment');
            $depts =& $hFDept->departmentsByField($field->getVar('id'), true);
            $fld_controltype = $field->getVar('controltype');
            $fld_datatype = $field->getVar('datatype');
            $fld_departments = array_keys($depts);
            $fld_name = $field->getVar('name');
            $fld_fieldname = $field->getVar('fieldname');
            $fld_description = $field->getVar('description');
            $fld_required = $field->getVar('required');
            $fld_length = $field->getVar('fieldlength');
            $fld_weight = $field->getVar('weight');
            $fld_defaultvalue = $field->getVar('defaultvalue');
            $fld_values = _formatValues($field->getVar('fieldvalues'));
            $fld_validation = $field->getVar('validation');
        }
        //Display Field modification
        xoops_cp_header();
        echo $oAdminButton->renderButtons('manfields');
        //Edit Field Form
        $controls = xhelpGetControlArray();
        $control_select = new XoopsFormSelect(_AM_XHELP_TEXT_CONTROLTYPE, 'fld_controltype', $fld_controltype);
        $control_select->setDescription(_AM_XHELP_TEXT_CONTROLTYPE_DESC);
        foreach ($controls as $key => $control) {
            $control_select->addOption($key, $control['label']);
        }
        $datatypes = array(_XHELP_DATATYPE_TEXT => _XHELP_DATATYPE_TEXT, _XHELP_DATATYPE_NUMBER_INT => _XHELP_DATATYPE_NUMBER_INT, _XHELP_DATATYPE_NUMBER_DEC => _XHELP_DATATYPE_NUMBER_DEC);
        $datatype_select = new XoopsFormSelect(_AM_XHELP_TEXT_DATATYPE, 'fld_datatype', $fld_datatype);
        $datatype_select->setDescription(_AM_XHELP_TEXT_DATATYPE_DESC);
        $datatype_select->addOptionArray($datatypes);
        $hDepts =& xhelpGetHandler('department');
        $depts =& $hDepts->getObjects();
        $dept_select = new XoopsFormSelect(_AM_XHELP_TEXT_DEPARTMENTS, 'fld_departments', $fld_departments, 5, true);
        $dept_select->setDescription(_AM_XHELP_TEXT_DEPT_DESC);
        foreach ($depts as $obj) {
            $dept_select->addOption($obj->getVar('id'), $obj->getVar('department'));
        }
        unset($depts);
        if (!$field_errors === false) {
            xhelpRenderErrors($field_errors, xhelpMakeURI(XHELP_ADMIN_URL . '/fields.php', array('op' => 'clearEditSession', 'id' => $fld_id)));
        }
        $form = new xhelpForm(_AM_XHELP_EDIT_FIELD, 'edit_field', xhelpMakeURI(XHELP_ADMIN_URL . '/fields.php', array('op' => 'editfield', 'id' => $fld_id)));
        $nameEle = new XoopsFormText(_AM_XHELP_TEXT_NAME, 'fld_name', 30, 64, $fld_name);
        $nameEle->setDescription(_AM_XHELP_TEXT_NAME_DESC);
        $form->addElement($nameEle);
        $fieldnameEle = new XoopsFormText(_AM_XHELP_TEXT_FIELDNAME, 'fld_fieldname', 30, 64, $fld_fieldname);
        $fieldnameEle->setDescription(_AM_XHELP_TEXT_FIELDNAME_DESC);
        $form->addElement($fieldnameEle);
        $descriptionEle = new XoopsFormTextArea(_AM_XHELP_TEXT_DESCRIPTION, 'fld_description', $fld_description, 5, 60);
        $descriptionEle->setDescription(_AM_XHELP_TEXT_DESCRIPTION_DESC);
        $form->addElement($descriptionEle);
        $form->addElement($dept_select);
        $form->addElement($control_select);
        $form->addElement($datatype_select);
        $required = new XoopsFormRadioYN(_AM_XHELP_TEXT_REQUIRED, 'fld_required', $fld_required);
        $required->setDescription(_AM_XHELP_TEXT_REQUIRED_DESC);
        $form->addElement($required);
        $lengthEle = new XoopsFormText(_AM_XHELP_TEXT_LENGTH, 'fld_length', 5, 5, $fld_length);
        $lengthEle->setDescription(_AM_XHELP_TEXT_LENGTH_DESC);
        $form->addElement($lengthEle);
        $widthEle = new XoopsFormText(_AM_XHELP_TEXT_WEIGHT, 'fld_weight', 5, 5, $fld_weight);
        $widthEle->setDescription(_AM_XHELP_TEXT_WEIGHT_DESC);
        $form->addElement($widthEle);
        $regex_control = new xhelpFormRegex(_AM_XHELP_TEXT_VALIDATION, 'fld_valid', $fld_validation);
        $regex_control->setDescription(_AM_XHELP_TEXT_VALIDATION_DESC);
        $regex_control->addOptionArray($regex_array);
        $form->addElement($regex_control);
        $defaultValueEle = new XoopsFormText(_AM_XHELP_TEXT_DEFAULTVALUE, 'fld_defaultvalue', 30, 100, $fld_defaultvalue);
        $defaultValueEle->setDescription(_AM_XHELP_TEXT_DEFAULTVALUE_DESC);
        $form->addElement($defaultValueEle);
        $values = new XoopsFormTextArea(_AM_XHELP_TEXT_FIELDVALUES, 'fld_values', $fld_values, 5, 60);
        $values->setDescription(_AM_XHELP_TEXT_FIELDVALUES_DESC);
        $form->addElement($values);
        $btn_tray = new XoopsFormElementTray('');
        $btn_tray->addElement(new XoopsFormButton('', 'editField', _AM_XHELP_BUTTON_SUBMIT, 'submit'));
        $btn_tray->addElement(new XoopsFormButton('', 'cancel', _AM_XHELP_BUTTON_CANCEL));
        $btn_tray->addElement(new XoopsFormHidden('id', $fld_id));
        $form->addElement($btn_tray);
        echo $form->render();
        xhelpAdminFooter();
        xoops_cp_footer();
    } else {
        //Validate Field Information
        $has_errors = false;
        $errors = array();
        $values =& _parseValues($_POST['fld_values']);
        if (!($control = xhelpGetControl($_POST['fld_controltype']))) {
            $has_errors = true;
            $errors['fld_controltype'][] = _AM_XHELP_VALID_ERR_CONTROLTYPE;
        }
        $fld_needslength = $control['needs_length'];
        $fld_needsvalues = $control['needs_values'];
        //name field filled?
        if (trim($_POST['fld_name']) == '') {
            $has_errors = true;
            $errors['fld_name'][] = _AM_XHELP_VALID_ERR_NAME;
        }
        //fieldname filled
        if (trim($_POST['fld_fieldname']) == '') {
            $has_errors = true;
            $errors['fld_fieldname'][] = _AM_XHELP_VALID_ERR_FIELDNAME;
        }
        //fieldname unique?
        $crit = new CriteriaCompo(new Criteria('id', $fld_id, '!='));
        $crit->add(new Criteria('fieldname', $_POST['fld_fieldname']));
        if ($hField->getCount($crit)) {
            $has_errors = true;
            $errors['fld_fieldname'][] = _AM_XHELP_VALID_ERR_FIELDNAME_UNIQUE;
        }
        //Length filled
        if (intval($_POST['fld_length']) == 0 && $fld_needslength == true) {
            $has_errors = true;
            $errors['fld_length'][] = sprintf(_AM_XHELP_VALID_ERR_LENGTH, _XHELP_FIELD_MINLEN, _XHELP_FIELD_MAXLEN);
        }
        //default value in value set?
        if (count($values)) {
            if (!in_array($_POST['fld_defaultvalue'], $values, true) && !array_key_exists($_POST['fld_defaultvalue'], $values)) {
                $has_errors = true;
                $errors['fld_defaultvalue'][] = _AM_XHELP_VALID_ERR_DEFAULTVALUE;
            }
            //length larger than longest value?
            $length = intval($_POST['fld_length']);
            foreach ($values as $key => $value) {
                if (strlen($key) > $length) {
                    $has_errors = true;
                    $errors['fld_values'][] = sprintf(_AM_XHELP_VALID_ERR_VALUE_LENGTH, htmlentities($key), $length);
                }
            }
        } elseif ($fld_needsvalues) {
            $has_errors = true;
            $errors['fld_values'][] = _AM_XHELP_VALID_ERR_VALUE;
        }
        if ($has_errors) {
            $afield = array();
            $afield['name'] = $_POST['fld_name'];
            $afield['description'] = $_POST['fld_description'];
            $afield['fieldname'] = $_POST['fld_fieldname'];
            $afield['departments'] = $_POST['fld_departments'];
            $afield['controltype'] = $_POST['fld_controltype'];
            $afield['datatype'] = $_POST['fld_datatype'];
            $afield['required'] = $_POST['fld_required'];
            $afield['weight'] = $_POST['fld_weight'];
            $afield['defaultvalue'] = $_POST['fld_defaultvalue'];
            $afield['values'] = $_POST['fld_values'];
            $afield['length'] = $_POST['fld_length'];
            $afield['validation'] = $_POST['fld_valid_select'] == $_POST['fld_valid_txtbox'] ? $_POST['fld_valid_select'] : $_POST['fld_valid_txtbox'];
            $session->set('xhelp_editField_' . $fld_id, $afield);
            $session->set('xhelp_editFieldErrors_' . $fld_id, $errors);
            //Redirect to edit page (display errors);
            header('Location: ' . xhelpMakeURI(XHELP_ADMIN_URL . '/fields.php', array('op' => 'editfield', 'id' => $fld_id), false));
            exit;
        }
        //Store Modified Field info
        $field->setVar('name', $_POST['fld_name']);
        $field->setVar('description', $_POST['fld_description']);
        $field->setVar('fieldname', $_POST['fld_fieldname']);
        $field->setVar('controltype', $_POST['fld_controltype']);
        $field->setVar('datatype', $_POST['fld_datatype']);
        $field->setVar('fieldlength', $_POST['fld_length']);
        $field->setVar('required', $_POST['fld_required']);
        $field->setVar('weight', $_POST['fld_weight']);
        $field->setVar('defaultvalue', $_POST['fld_defaultvalue']);
        $field->setVar('validation', $_POST['fld_valid_select'] == $_POST['fld_valid_txtbox'] ? $_POST['fld_valid_select'] : $_POST['fld_valid_txtbox']);
        $field->setValues($values);
        $field->addDepartments($_POST['fld_departments']);
        if ($hField->insert($field)) {
            _clearEditSessionVars($fld_id);
            redirect_header(xhelpMakeURI(XHELP_ADMIN_URL . '/fields.php'), 3, _AM_XHELP_MSG_FIELD_UPD_OK);
        } else {
            redirect_header(xhelpMakeURI(XHELP_ADMIN_URL . '/fields.php', array('op' => 'editfield', 'id' => $fld_id), false), 3, _AM_XHELP_MSG_FIELD_UPD_ERR);
        }
    }
}