Example #1
0
function removeDepts()
{
    global $xoopsDB;
    //Needs force on delete
    $hConfig =& xoops_gethandler('config');
    // Select the config from the xoops_config table
    $crit = new Criteria('conf_name', 'xhelp_defaultDept');
    $config =& $hConfig->getConfigs($crit);
    if (count($config) > 0) {
        $xhelp_config = $config[0]->getVar('conf_id');
    } else {
        return false;
    }
    // Remove the config options
    $hConfigOption =& xhelpGetHandler('configoption');
    $crit = new Criteria('conf_id', $xhelp_config);
    $configOptions =& $hConfigOption->getObjects($crit);
    if (count($configOptions) > 0) {
        foreach ($configOptions as $option) {
            if (!$hConfigOption->deleteAll($option, true)) {
                // Remove each config option
                return false;
            }
        }
    } else {
        // If no config options were found
        return $xhelp_config;
    }
    return $xhelp_config;
}
Example #2
0
 /**
  * Call Backback function for 'delete_ticket'
  * @param	xhelpTicket $ticket Ticket being deleted
  * @return  bool True on success, false on error
  * @access	public
  */
 function delete_ticket($ticket)
 {
     $hStatus = xhelpGetHandler('status');
     $status =& $hStatus->get($ticket->getVar('status'));
     if ($status->getVar('state') == XHELP_STATE_UNRESOLVED) {
         return $this->_clearPerfImages();
     }
 }
Example #3
0
 /**
  * Event: new_faq
  * Triggered after FAQ addition
  * @param xhelpTicket $ticket Ticket used as base for FAQ
  * @param xhelpFaq $faq FAQ that was added
  */
 function new_faq($ticket, $faq)
 {
     global $xoopsUser;
     //Create a new solution from the supplied ticket / faq
     $hTicketSol =& xhelpGetHandler('ticketSolution');
     $sol =& $hTicketSol->create();
     $sol->setVar('ticketid', $ticket->getVar('id'));
     $sol->setVar('url', $faq->getVar('url'));
     $sol->setVar('title', $faq->getVar('subject'));
     $sol->setVar('uid', $xoopsUser->getVar('uid'));
     return $hTicketSol->addSolution($ticket, $sol);
 }
 function staffByDept($deptid)
 {
     $mc =& xhelpGetModuleConfig();
     $field = $mc['xhelp_displayName'] == 1 ? 'uname' : 'name';
     $deptid = intval($deptid);
     $hMembership =& xhelpGetHandler('membership');
     $staff =& $hMembership->xoopsUsersByDept($deptid);
     $aStaff = array();
     $aStaff[] = array('uid' => 0, 'name' => _XHELP_MESSAGE_NOOWNER);
     foreach ($staff as $s) {
         $aStaff[] = array('uid' => $s->getVar('uid'), 'name' => $s->getVar($field));
     }
     return $aStaff;
 }
 function statusesByState($state)
 {
     $state = intval($state);
     $hStatus =& xhelpGetHandler('status');
     if ($state == -1) {
         // If select all is chosen
         $statuses =& $hStatus->getObjects(null, true);
     } else {
         $statuses =& $hStatus->getStatusesByState($state);
     }
     $aStatuses = array();
     $aStatuses[] = array('key' => -1, 'value' => _XHELP_TEXT_SELECT_ALL);
     foreach ($statuses as $status) {
         $aStatuses[] = array('key' => $status->getVar('id'), 'value' => $status->getVar('description'));
     }
     return $aStatuses;
 }
Example #6
0
 /**
  * getCategories: retrieve the categories for the module
  * @return ARRAY Array of xhelpFaqCategory
  */
 function &getCategories()
 {
     $ret = array();
     // Create an instance of the xhelpFaqCategoryHandler
     $hFaqCategory =& xhelpGetHandler('faqCategory');
     // Get all the categories for the application
     $hSmartCategory =& sf_gethandler('category');
     $categories =& $hSmartCategory->getCategories(0, 0, -1);
     //Convert the module specific category to the
     //xhelpFaqCategory object for standarization
     foreach ($categories as $category) {
         $faqcat = $hFaqCategory->create();
         $faqcat->setVar('id', $category->getVar('categoryid'));
         $faqcat->setVar('parent', $category->getVar('parentid'));
         $faqcat->setVar('name', $category->getVar('name'));
         $ret[] = $faqcat;
     }
     unset($categories);
     return $ret;
 }
Example #7
0
 /**
  * @return array of xhelpFaqCategory objects
  */
 function &getCategories()
 {
     global $xoopsDB;
     $ret = array();
     // Create an instance of the xhelpFaqCategoryHandler
     $hFaqCategory =& xhelpGetHandler('faqCategory');
     $sql = sprintf("SELECT cat_ID, cat_name, category_parent FROM %s", $xoopsDB->prefix("wp_categories"));
     $result = $xoopsDB->query($sql);
     if (!$result) {
         return $ret;
     }
     //Convert the module specific category to the
     //xhelpFaqCategory object for standarization
     while ($myrow = $xoopsDB->fetchArray($result)) {
         $faqcat = $hFaqCategory->create();
         $faqcat->setVar('id', $myrow['cat_ID']);
         $faqcat->setVar('name', $myrow['cat_name']);
         $faqcat->setVar('parent', $myrow['category_parent']);
         $ret[] = $faqcat;
     }
     return $ret;
 }
 /**
  * Create a new ticket object
  * @param object Reference to a {@link xhelpEmailParser} object
  * @param object Current {@link xoopsUser} object
  * @param object {@link xhelpDepartment} Ticket Department
  * @param object {@link xhelpDepartmentEmailServer} Originating Email Server
  * @return bool
  * @access public
  */
 function createTicket(&$mailParser, &$xoopsUser, &$department, &$server)
 {
     //get ticket handler
     $hTicket =& xhelpGetHandler('ticket');
     $ticket =& $hTicket->create();
     //
     $ticket->setVar('uid', $xoopsUser->uid());
     $ticket->setVar('subject', $mailParser->getSubject());
     $ticket->setVar('department', $department->getVar('id'));
     $ticket->setVar('description', $mailParser->getBody());
     $ticket->setVar('priority', 3);
     $ticket->setVar('posted', time());
     $ticket->setVar('userIP', _XHELP_EMAIL_SCANNER_IP_COLUMN);
     $ticket->setVar('serverid', $server->getVar('id'));
     $ticket->createEmailHash($mailParser->getEmail());
     //
     if ($hTicket->insert($ticket)) {
         $this->_ticket = $ticket;
         return true;
     } else {
         return false;
     }
 }
Example #9
0
function addFaq_action()
{
    global $xoopsUser, $_eventsrv;
    $hTicket =& xhelpGetHandler('ticket');
    // Retrieve ticket information
    $ticketid = $_POST['ticketid'];
    $ticket =& $hTicket->get($ticketid);
    $adapter =& xhelpFaqAdapterFactory::getFaqAdapter();
    $faq =& $adapter->createFaq();
    // @todo - Make subject user editable
    $faq->setVar('subject', $_POST['subject']);
    $faq->setVar('problem', $_POST['problem']);
    $faq->setVar('solution', $_POST['solution']);
    // BTW - XOBJ_DTYPE_ARRAY vars must be serialized prior to calling setVar in XOOPS 2.0
    $faq->setVar('categories', serialize($_POST['categories']));
    if ($adapter->storeFaq($faq)) {
        // Todo: Run events here
        $_eventsrv->trigger('new_faq', array(&$ticket, &$faq));
        redirect_header(XHELP_BASE_URL . "/ticket.php?id={$ticketid}", 3, _XHELP_MESSAGE_ADD_FAQ);
    } else {
        redirect_header(XHELP_BASE_URL . "/ticket.php?id={$ticketid}", 3, _XHELP_MESSAGE_ERR_ADD_FAQ);
    }
}
Example #10
0
 function rename($ticketid, $responseid = 0)
 {
     $ticketid = intval($ticketid);
     $responseid = intval($responseid);
     $old_ticketid = $this->getVar('ticketid');
     $old_responseid = $this->getVar('responseid');
     $filename = $this->getVar('filename');
     if ($old_responseid != 0 && $responseid != 0) {
         // Was a response and is going to be a response
         $newFilename = str_replace("_" . $old_responseid . "_", "_" . $responseid . "_", $filename);
         $newFilename = str_replace($old_ticketid . "_", $ticketid . "_", $newFilename);
     } elseif ($old_responseid != 0 && $responseid == 0) {
         // Was a response and is part of the ticket now
         $newFilename = str_replace("_" . $old_responseid . "_", "_", $filename);
         $newFilename = str_replace($old_ticketid . "_", $ticketid . "_", $newFilename);
     } elseif ($old_responseid == 0 && $responseid != 0) {
         // Was part of the ticket, now going to a response
         $newFilename = str_replace($old_ticketid . "_", $ticketid . "_" . $responseid . "_", $filename);
     } elseif ($old_responseid == 0 && $responseid == 0) {
         // Was part of the ticket, and is part of the ticket now
         $newFilename = str_replace($old_ticketid . "_", $ticketid . "_", $filename);
     }
     $hFile =& xhelpGetHandler('file');
     $this->setVar('filename', $newFilename);
     $this->setVar('ticketid', $ticketid);
     $this->setVar('responseid', $responseid);
     if ($hFile->insert($this, true)) {
         $success = true;
     } else {
         $success = false;
     }
     $ret = false;
     if ($success) {
         $ret = $this->renameAtFS($filename, $newFilename);
     }
     return $ret;
 }
Example #11
0
 /**
  * Class Constructor
  *
  * @param mixed $ticketid null for a new object, hash table for an existing object
  * @return none
  * @access public
  */
 function xhelpTicketValues($id = null)
 {
     $this->initVar('ticketid', XOBJ_DTYPE_INT, null, false);
     $hFields =& xhelpGetHandler('ticketField');
     $fields =& $hFields->getObjects(null, true);
     foreach ($fields as $field) {
         $key = $field->getVar('fieldname');
         $datatype = $this->_getDataType($field->getVar('datatype'), $field->getVar('controltype'));
         $value = $this->_getValueFromXoopsDataType($datatype);
         $required = $field->getVar('required');
         $maxlength = $field->getVar('fieldlength') < 50 ? $field->getVar('fieldlength') : 50;
         $options = '';
         $this->initVar($key, $datatype, null, $required, $maxlength, $options);
         $this->_fields[$key] = $field->getVar('datatype') == _XHELP_DATATYPE_TEXT ? "%s" : "%d";
     }
     $this->_fields['ticketid'] = "%u";
     if (isset($id)) {
         if (is_array($id)) {
             $this->assignVars($id);
         }
     } else {
         $this->setNew();
     }
 }
Example #12
0
function testMailbox()
{
    $hDeptServers =& xhelpGetHandler('departmentMailBox');
    $server = $hDeptServers->create();
    $server->setVar('emailaddress', $_POST['emailaddress']);
    $server->setVar('server', $_POST['server']);
    $server->setVar('serverport', $_POST['port']);
    $server->setVar('username', $_POST['username']);
    $server->setVar('password', $_POST['password']);
    $server->setVar('priority', $_POST['priority']);
    echo "<html>";
    echo "<head>";
    echo "<link rel='stylesheet' type='text/css' media'screen' href='" . XOOPS_URL . "/xoops.css' />\r\n          <link rel='stylesheet' type='text/css' media='screen' href='" . xoops_getcss() . "' />\r\n          <link rel='stylesheet' type='text/css' media='screen' href='" . XOOPS_URL . "/modules/system/style.css' />";
    echo "</head>";
    echo "<body>";
    echo "<table style='margin:0; padding:0;' class='outer'>";
    if (@$server->connect()) {
        //Connection Succeeded
        echo "<tr><td class='head'>Connection Successful!</td></tr>";
    } else {
        //Connection Failed
        echo "<tr class='head'><td>Connection Failed!</td></tr>";
        echo "<tr class='even'><td>" . $server->getHtmlErrors() . "</td></tr>";
    }
    echo "</table>";
    echo "</body>";
    echo "</html>";
}
 /** get a reference from the database.
 
     @return array  reference( category_id => ...., content => ....)
     @param  string id
     */
 function getReference($doc_id)
 {
     $hTicket = xhelpGetHandler('ticket');
     $ticket = $hTicket->get($doc_id);
     $ref = array();
     if (!$ticket) {
         return $ref;
     }
     $ref['id'] = $ticket->getVar('ticketid');
     $ref['content'] = $ticket->getVar('subject') . "\r\n" . $ticket->getVar('description');
     $ref['category_id'] = 'P' . $ticket->getVar('ticketid');
     return $ref;
 }
Example #14
0
        $hTicket =& xhelpGetHandler('ticket');
        if (isset($_POST['ticketid'])) {
            $xhelp_id = $_POST['ticketid'];
        }
        $ticketInfo =& $hTicket->get($xhelp_id);
        // Retrieve ticket information
        if ($hTicket->delete(&$ticketInfo)) {
            $message = _XHELP_MESSAGE_DELETE_TICKET;
            $_eventsrv->trigger('delete_ticket', array(&$ticketInfo));
        } else {
            $message = _XHELP_MESSAGE_DELETE_TICKET_ERROR;
        }
        redirect_header(XHELP_BASE_URL . '/index.php', 3, $message);
    } elseif (isset($_POST['delete_responseTpl'])) {
        //Should only the owner of a template be able to delete it?
        $hResponseTpl = xhelpGetHandler('responseTemplates');
        $displayTpl =& $hResponseTpl->get($_POST['tplID']);
        if ($xoopsUser->getVar('uid') != $displayTpl->getVar('uid')) {
            $message = _NOPERM;
        } else {
            if ($hResponseTpl->delete($displayTpl)) {
                $message = _XHELP_MESSAGE_DELETE_RESPONSE_TPL;
                $_eventsrv->trigger('delete_responseTpl', array($displayTpl));
            } else {
                $message = _XHELP_MESSAGE_DELETE_RESPONSE_TPL_ERROR;
            }
        }
        redirect_header(XHELP_BASE_URL . "/profile.php", 3, $message);
    }
} else {
    // If not a user
Example #15
0
function manageStatus()
{
    global $oAdminButton, $aSortBy, $aOrderBy, $aLimitBy, $order, $limit, $start, $sort;
    $hStatus =& xhelpGetHandler('status');
    if (isset($_POST['changeDefaultStatus'])) {
        xhelpSetMeta("default_status", $_POST['default']);
    }
    if (isset($_POST['newStatus'])) {
        if ($_POST['desc'] == '') {
            // If no description supplied
            $message = _AM_XHELP_MESSAGE_NO_DESC;
            redirect_header(XHELP_ADMIN_URL . "/status.php?op=manageStatus", 3, $message);
        }
        $newStatus =& $hStatus->create();
        $newStatus->setVar('state', intval($_POST['state']));
        $newStatus->setVar('description', $_POST['desc']);
        if ($hStatus->insert($newStatus)) {
            header("Location: " . XHELP_ADMIN_URL . "/status.php?op=manageStatus");
        } else {
            $message = _AM_MESSAGE_ADD_STATUS_ERR;
            redirect_header(XHELP_ADMIN_URL . "/status.php?op=manageStatus", 3, $message);
        }
    }
    xoops_cp_header();
    echo $oAdminButton->renderButtons('manStatus');
    echo "<form method='post' action='" . XHELP_ADMIN_URL . "/status.php?op=manageStatus'>";
    echo "<table width='100%' cellspacing='1' class='outer'>\r\n          <tr><th colspan='2'><label>" . _AM_XHELP_TEXT_ADD_STATUS . "</label></th></tr>";
    echo "<tr><td class='head' width='20%'>" . _AM_XHELP_TEXT_DESCRIPTION . "</td>\r\n              <td class='even'>\r\n                  <input type='text' name='desc' value='' class='formButton' />\r\n              </td>\r\n          </tr>";
    echo "<tr><td class='head' width='20%'>" . _AM_XHELP_TEXT_STATE . "</td><td class='even'>\r\n              <select name='state'>\r\n              <option value='1'>" . xhelpGetState(1) . "</option>\r\n              <option value='2'>" . xhelpGetState(2) . "</option>\r\n          </select></td></tr>";
    echo "<tr><td class='foot' colspan='2'><input type='submit' name='newStatus' value='" . _AM_XHELP_TEXT_ADD_STATUS . "' class='formButton' /></td></tr>";
    echo "</table></form>";
    // Get list of existing statuses
    $crit = new Criteria('', '');
    $crit->setOrder($order);
    $crit->setSort($sort);
    $crit->setLimit($limit);
    $crit->setStart($start);
    $statuses =& $hStatus->getObjects($crit);
    $total = $hStatus->getCount($crit);
    $aStatuses = array();
    foreach ($statuses as $status) {
        $aStatuses[$status->getVar('id')] = $status->getVar('description');
    }
    if (!($default_status = xhelpGetMeta("default_status"))) {
        xhelpSetMeta("default_status", "1");
        $default_status = 1;
    }
    $form = new xhelpForm(_AM_XHELP_TEXT_DEFAULT_STATUS, 'default_status', xhelpMakeURI(XHELP_ADMIN_URL . '/status.php', array('op' => 'manageStatus')));
    $status_select = new XoopsFormSelect(_AM_XHELP_TEXT_STATUS, 'default', $default_status);
    $status_select->addOptionArray($aStatuses);
    $btn_tray = new XoopsFormElementTray('');
    $btn_tray->addElement(new XoopsFormButton('', 'changeDefaultStatus', _AM_XHELP_BUTTON_SUBMIT, 'submit'));
    $form->addElement($status_select);
    $form->addElement($btn_tray);
    $form->setLabelWidth('20%');
    echo $form->render();
    $nav = new XoopsPageNav($total, $limit, $start, 'start', "op=manageStatus&amp;limit={$limit}");
    echo "<form action='" . XHELP_ADMIN_URL . "/status.php?op=manageStatus' style='margin:0; padding:0;' method='post'>";
    echo "<table width='100%' cellspacing='1' class='outer'>";
    echo "<tr><td align='right'>" . _AM_XHELP_TEXT_SORT_BY . "\r\n                  <select name='sort'>";
    foreach ($aSortBy as $value => $text) {
        $sort == $value ? $selected = "selected='selected'" : ($selected = '');
        echo "<option value='{$value}' {$selected}>{$text}</option>";
    }
    echo "</select>\r\n                &nbsp;&nbsp;&nbsp;\r\n                  " . _AM_XHELP_TEXT_ORDER_BY . "\r\n                  <select name='order'>";
    foreach ($aOrderBy as $value => $text) {
        $order == $value ? $selected = "selected='selected'" : ($selected = '');
        echo "<option value='{$value}' {$selected}>{$text}</option>";
    }
    echo "</select>\r\n                  &nbsp;&nbsp;&nbsp;\r\n                  " . _AM_XHELP_TEXT_NUMBER_PER_PAGE . "\r\n                  <select name='limit'>";
    foreach ($aLimitBy as $value => $text) {
        $limit == $value ? $selected = "selected='selected'" : ($selected = '');
        echo "<option value='{$value}' {$selected}>{$text}</option>";
    }
    echo "</select>\r\n                  <input type='submit' name='status_sort' id='status_sort' value='" . _AM_XHELP_BUTTON_SUBMIT . "' />\r\n              </td>\r\n          </tr>";
    echo "</table></form>";
    echo "<table width='100%' cellspacing='1' class='outer'>\r\n          <tr><th colspan='4'><label>" . _AM_XHELP_TEXT_MANAGE_STATUSES . "</label></th></tr>";
    echo "<tr class='head'>\r\n              <td>" . _AM_XHELP_TEXT_ID . "</td>\r\n              <td>" . _AM_XHELP_TEXT_DESCRIPTION . "</td>\r\n              <td>" . _AM_XHELP_TEXT_STATE . "</td>\r\n              <td>" . _AM_XHELP_TEXT_ACTIONS . "</td>\r\n          </tr>";
    foreach ($statuses as $status) {
        echo "<tr class='even'><td>" . $status->getVar('id') . "</td><td>" . $status->getVar('description') . "</td>\r\n              <td>" . xhelpGetState($status->getVar('state')) . "</td>\r\n              <td>\r\n                  <a href='status.php?op=editStatus&amp;statusid=" . $status->getVar('id') . "'><img src='" . XHELP_IMAGE_URL . "/button_edit.png' title='" . _AM_XHELP_TEXT_EDIT . "' name='editStatus' /></a>&nbsp;\r\n                  <a href='status.php?op=deleteStatus&amp;statusid=" . $status->getVar('id') . "'><img src='" . XHELP_IMAGE_URL . "/button_delete.png' title='" . _AM_XHELP_TEXT_DELETE . "' name='deleteStatus' /></a></td></tr>\r\n              </td></tr>";
    }
    echo "</table>";
    echo "<div id='status_nav'>" . $nav->renderNav() . "</div>";
    xhelpAdminFooter();
    xoops_cp_footer();
}
Example #16
0
function upgradeDB()
{
    global $xoopsModule, $oAdminButton;
    $xoopsDB =& Database::getInstance();
    //1. Determine previous release
    //   *** Update this in sql/mysql.sql for each release **
    if (!xhelpTableExists('xhelp_meta')) {
        $ver = '0.5';
    } else {
        if (!($ver = xhelpGetMeta('version'))) {
            exit(_AM_XHELP_VERSION_ERR);
        }
    }
    $hStaff =& xhelpGetHandler('staff');
    $hMember =& xhelpGetHandler('membership');
    $hTicket =& xhelpGetHandler('ticket');
    $hXoopsMember =& xoops_gethandler('member');
    $hRole =& xhelpGetHandler('role');
    $mid = $xoopsModule->getVar('mid');
    xoops_cp_header();
    echo $oAdminButton->renderButtons('');
    echo "<h2>" . _AM_XHELP_UPDATE_DB . "</h2>";
    $ret = true;
    //2. Do All Upgrades necessary to make current
    //   Break statements are omitted on purpose
    switch ($ver) {
        case '0.5':
            set_time_limit(60);
            printf("<h3>" . _AM_XHELP_UPDATE_TO . "</h3>", '0.6');
            echo "<ul>";
            //Create meta table
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (metakey varchar(50) NOT NULL default '', metavalue varchar(255) NOT NULL default '', PRIMARY KEY (metakey)) ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_meta')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_meta'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_meta'));
            //Insert Current Version into table
            $qry = $xoopsDB->query(sprintf("INSERT INTO %s values('version', %s)", $xoopsDB->prefix('xhelp_meta'), $xoopsDB->quoteString($ver)));
            //Update xhelp_responses table
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD private INT(11) NOT NULL DEFAULT '0'", $xoopsDB->prefix('xhelp_responses')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_responses'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_responses'));
            //Retrieve uid's of all staff members
            $qry = $xoopsDB->query('SELECT uid FROM ' . $xoopsDB->prefix('xhelp_staff') . ' ORDER BY uid');
            //Get email addresses in user profile
            $staff = array();
            while ($arr = $xoopsDB->fetchArray($qry)) {
                $staff[$arr['uid']] = '';
            }
            $xoopsDB->freeRecordSet($qry);
            $query = 'SELECT uid, email FROM ' . $xoopsDB->prefix('users') . ' WHERE uid IN (' . implode(array_keys($staff), ',') . ')';
            $qry = $xoopsDB->query($query);
            while ($arr = $xoopsDB->fetchArray($qry)) {
                $staff[$arr['uid']] = $arr['email'];
            }
            $xoopsDB->freeRecordSet($qry);
            //Update xhelp_staff table
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD email varchar(255) NOT NULL default '' AFTER uid, ADD notify int(11) NOT NULL default '0'", $xoopsDB->prefix('xhelp_staff')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_staff'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_staff'));
            //Update existing staff records
            $staff_tbl = $xoopsDB->prefix('xhelp_staff');
            $notif_tbl = $xoopsDB->prefix('xoopsnotifications');
            $email_tpl = $xoopsModule->getInfo('_email_tpl');
            foreach ($staff as $uid => $email) {
                //get notifications for current user
                $usernotif = 0;
                $qry = $xoopsDB->query(sprintf("SELECT DISTINCT not_category, not_event FROM %s WHERE not_uid = %u AND not_category='dept' AND not_modid=%u", $notif_tbl, $uid, $mid));
                while ($arr = $xoopsDB->fetchArray($qry)) {
                    //Look for current event information in $email_tpl
                    foreach ($email_tpl as $tpl) {
                        if ($tpl['name'] == $arr['not_event'] && $tpl['category'] == $arr['not_category']) {
                            $usernotif = $usernotif | pow(2, $tpl['bit_value']);
                            break;
                        }
                    }
                }
                //Update xhelp_staff with user notifications & email address
                $ret = $ret && _runQuery(sprintf("UPDATE %s SET email = %s, notify = %u WHERE uid = %u", $staff_tbl, $xoopsDB->quoteString($email), $usernotif, $uid), sprintf(_AM_XHELP_MSG_UPDATESTAFF, $uid), sprintf(_AM_XHELP_MSG_UPDATESTAFF_ERR, $uid));
            }
            echo "</ul>";
        case '0.6':
            set_time_limit(60);
            //Do DB updates to make 0.7
            printf("<h3>" . _AM_XHELP_UPDATE_TO . "</h3>", '0.7');
            echo "<ul>";
            // change table names to lowercase
            $ret = $ret && _renameTable('xhelp_logMessages', 'xhelp_logmessages');
            $ret = $ret && _renameTable('xhelp_responseTemplates', 'xhelp_responsetemplates');
            $ret = $ret && _renameTable('xhelp_jStaffDept', 'xhelp_jstaffdept');
            $ret = $ret && _renameTable('xhelp_staffReview', 'xhelp_staffreview');
            $ret = $ret && _renameTable('xhelp_emailTpl', 'xhelp_emailtpl');
            // Remove unused table - xhelp_emailtpl
            $ret = $ret && _runQuery(sprintf("DROP TABLE %s", $xoopsDB->prefix('xhelp_emailtpl')), sprintf(_AM_XHELP_MSG_REMOVE_TABLE, 'xhelp_emailtpl'), sprintf(_AM_XHELP_MSG_NOT_REMOVE_TABLE, 'xhelp_emailtpl'));
            // xhelp_staff table - permTimestamp
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD permTimestamp INT(11) NOT NULL DEFAULT '0'", $xoopsDB->prefix('xhelp_staff')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_staff'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_staff'));
            //Update xhelp_tickets table
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY subject VARCHAR(100) NOT NULL default ''", $xoopsDB->prefix('xhelp_tickets')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_tickets'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_tickets'));
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD (serverid INT(11) DEFAULT NULL,\r\n                                                             emailHash VARCHAR(100) DEFAULT NULL,\r\n                                                             email VARCHAR(100) DEFAULT NULL,\r\n                                                             overdueTime INT(11) NOT NULL DEFAULT '0',\r\n                                                             KEY emailHash (emailHash))", $xoopsDB->prefix('xhelp_tickets')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_tickets'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_tickets'));
            // Create xhelp_department_mailbox table
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment,\r\n                                                          departmentid int(11) default NULL,\r\n                                                          emailaddress varchar(255) default NULL,\r\n                                                          server varchar(50) default NULL,\r\n                                                          serverport int(11) default NULL,\r\n                                                          username varchar(50) default NULL,\r\n                                                          password varchar(50) default NULL,\r\n                                                          priority tinyint(4) default NULL,\r\n                                                          mboxtype int(11) NOT NULL default 1,\r\n                                                          PRIMARY KEY  (id),\r\n                                                          UNIQUE KEY id (id),\r\n                                                          KEY departmentid (departmentid),\r\n                                                          KEY emailaddress (emailaddress),\r\n                                                          KEY mboxtype (mboxtype)\r\n                                                         )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_department_mailbox')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_department_mailbox'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_department_mailbox'));
            // Create xhelp_mailevent table
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment,\r\n                                                           mbox_id int(11) NOT NULL default '0',\r\n                                                           event_desc text,\r\n                                                           event_class int(11) NOT NULL default '0',\r\n                                                           posted int(11) NOT NULL default '0',\r\n                                                           PRIMARY KEY(id)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_mailevent')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_mailevent'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_mailevent'));
            // Create xhelp_roles table
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment,\r\n                                                          name varchar(35) NOT NULL default '',\r\n                                                          description mediumtext,\r\n                                                          tasks int(11) NOT NULL default '0',\r\n                                                          PRIMARY KEY(id)\r\n                                                         )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_roles')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_roles'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_roles'));
            // Create xhelp_staffroles table
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (uid int(11) NOT NULL default '0',\r\n                                                         roleid int(11) NOT NULL default '0',\r\n                                                         deptid int(11) NOT NULL default '0',\r\n                                                         PRIMARY KEY(uid, roleid, deptid)\r\n                                                        )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_staffroles')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_staffroles'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_staffroles'));
            // Add default roles to db
            if (!($hasRoles = xhelpCreateRoles())) {
                echo "<li>" . _AM_XHELP_MESSAGE_DEF_ROLES_ERROR . "</li>";
            } else {
                echo "<li>" . _AM_XHELP_MESSAGE_DEF_ROLES . "</li>";
            }
            // Set all staff members to have admin permission role
            if ($staff =& $hStaff->getObjects()) {
                foreach ($staff as $stf) {
                    $uid = $stf->getVar('uid');
                    $depts = $hMember->membershipByStaff($uid, true);
                    if ($hStaff->addStaffRole($uid, 1, 0)) {
                        echo "<li>" . sprintf(_AM_XHELP_MSG_GLOBAL_PERMS, $uid) . "</li>";
                    }
                    foreach ($depts as $dept) {
                        $deptid = $dept->getVar('id');
                        if ($hStaff->addStaffRole($uid, 1, $deptid)) {
                            // Departmental permissions
                            echo "<li>" . sprintf(_AM_XHELP_MSG_UPD_PERMS, $uid, $dept->getVar('department')) . "</li>";
                        }
                    }
                    $stf->setVar('permTimestamp', time());
                    // Set initial value for permTimestamp field
                    if (!$hStaff->insert($stf)) {
                        echo "<li>" . sprintf(_AM_XHELP_MSG_UPDATESTAFF_ERR, $uid) . "</li>";
                    } else {
                        echo "<li>" . sprintf(_AM_XHELP_MSG_UPDATESTAFF, $uid) . "</li>";
                    }
                }
            }
            echo "</ul>";
        case '0.7':
            set_time_limit(60);
            //Do DB updates to make 0.71
            printf("<h3>" . _AM_XHELP_UPDATE_TO . "</h3>", '0.71');
            echo "<ul>";
            echo "</ul>";
        case '0.71':
            set_time_limit(60);
            //Do DB updates to make 0.75
            printf("<h3>" . _AM_XHELP_UPDATE_TO . "</h3>", '0.75');
            echo "<ul>";
            //Changes for php5 compabibility
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY lastUpdated int(11) NOT NULL default '0'", $xoopsDB->prefix('xhelp_logmessages')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_logmessages'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_logmessages'));
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY department int(11) NOT NULL default '0'", $xoopsDB->prefix('xhelp_jstaffdept')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_jstaffdept'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_jstaffdept'));
            // Create table for email template information
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (notif_id int(11) NOT NULL default '0',\r\n                                                           staff_setting int(11) NOT NULL default '0',\r\n                                                           user_setting int(11) NOT NULL default '0',\r\n                                                           staff_options mediumtext NOT NULL,\r\n                                                           PRIMARY KEY (notif_id)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_notifications')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_notifications'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_notifications'));
            // Add xhelp_status table
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment,\r\n                                                           state int(11) NOT NULL default '0',\r\n                                                           description varchar(50) NOT NULL default '',\r\n                                                           PRIMARY KEY(id),\r\n                                                           KEY state (state)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_status')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_status'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_status'));
            // Give default statuses for upgrade
            $hStatus =& xhelpGetHandler('status');
            $startStatuses = array(_XHELP_STATUS0 => 1, _XHELP_STATUS1 => 1, _XHELP_STATUS2 => 2);
            $count = 1;
            set_time_limit(60);
            foreach ($startStatuses as $desc => $state) {
                $newStatus =& $hStatus->create();
                $newStatus->setVar('id', $count);
                $newStatus->setVar('description', $desc);
                $newStatus->setVar('state', $state);
                if (!$hStatus->insert($newStatus)) {
                    echo "<li>" . sprintf(_AM_XHELP_MSG_ADD_STATUS_ERR, $desc) . "</li>";
                } else {
                    echo "<li>" . sprintf(_AM_XHELP_MSG_ADD_STATUS, $desc) . "</li>";
                }
                $count++;
            }
            // Change old status values to new status values
            $oldStatuses = array(2 => 3, 1 => 2, 0 => 1);
            foreach ($oldStatuses as $cStatus => $newStatus) {
                $crit = new Criteria('status', $cStatus);
                $success = $hTicket->updateAll('status', $newStatus, $crit);
            }
            if ($success) {
                echo "<li>" . _AM_XHELP_MSG_CHANGED_STATUS . "</li>";
            } else {
                echo "<li>" . _AM_XHELP_MSG_CHANGED_STATUS_ERR . "</li>";
            }
            // Add xhelp_ticket_submit_emails table
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (ticketid int(11) NOT NULL default '0',\r\n                                                           uid int(11) NOT NULL default '0',\r\n                                                           email varchar(100) NOT NULL default '',\r\n                                                           suppress int(11) NOT NULL default '0',\r\n                                                           PRIMARY KEY(ticketid, email)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_submit_emails')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_submit_emails'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_submit_emails'));
            // Add records to xhelp_ticket_submit_emails for existing tickets
            $count = $hTicket->getCount();
            $batchsize = 100;
            $crit = new Criteria('', '');
            $crit->setLimit($batchsize);
            $i = 0;
            while ($i <= $count) {
                set_time_limit(60);
                $crit->setStart($i);
                $tickets =& $hTicket->getObjects($crit);
                $all_users = array();
                foreach ($tickets as $ticket) {
                    $all_users[$ticket->getVar('uid')] = $ticket->getVar('uid');
                }
                $crit = new Criteria('uid', "(" . implode(array_keys($all_users), ',') . ")", 'IN');
                $users =& $hXoopsMember->getUsers($crit, true);
                foreach ($users as $user) {
                    $all_users[$user->getVar('uid')] = $user->getVar('email');
                }
                unset($users);
                foreach ($tickets as $ticket) {
                    set_time_limit(60);
                    $ticket_uid = $ticket->getVar('uid');
                    if (array_key_exists($ticket_uid, $all_users)) {
                        $ticket_email = $all_users[$ticket_uid];
                        $success = $ticket->addSubmitter($ticket_email, $ticket_uid);
                    }
                }
                unset($tickets);
                //increment
                $i += $batchsize;
            }
            set_time_limit(60);
            // Update xhelp_roles Admin record with new value (2047)
            $crit = new Criteria('tasks', 511);
            $admin_roles =& $hRole->getObjects($crit);
            foreach ($admin_roles as $role) {
                $role->setVar('tasks', 2047);
                if ($hRole->insert($role)) {
                    echo "<li>" . sprintf(_AM_XHELP_MSG_UPDATE_ROLE, $role->getVar('name')) . "</li>";
                } else {
                    echo "<li>" . sprintf(_AM_XHELP_MSG_UPDATE_ROLE_ERR, $role->getVar('name')) . "</li>";
                }
            }
            set_time_limit(60);
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD (active INT(11) NOT NULL DEFAULT 1,\r\n                                                          KEY active (active))", $xoopsDB->prefix('xhelp_department_mailbox')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_department_mailbox'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_department_mailbox'));
            // Add xhelp_saved_searches table
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment,\r\n                                                           uid int(11) NOT NULL default '0',\r\n                                                           name varchar(50) NOT NULL default '',\r\n                                                           search mediumtext NOT NULL,\r\n                                                           pagenav_vars mediumtext NOT NULL,\r\n                                                           PRIMARY KEY(id)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_saved_searches')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_saved_searches'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_saved_searches'));
            set_time_limit(60);
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (fieldid int(11) NOT NULL default '0',\r\n                                                           deptid int(11) NOT NULL default '0',\r\n                                                           PRIMARY KEY  (fieldid, deptid)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_field_departments')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_field_departments'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_field_departments'));
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (ticketid int(11) NOT NULL default '0',\r\n                                                           PRIMARY KEY  (ticketid)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_values')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_values'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_values'));
            set_time_limit(60);
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment,\r\n                                                           name varchar(64) NOT NULL default '',\r\n                                                           description tinytext NOT NULL,\r\n                                                           fieldname varchar(64) NOT NULL default '',\r\n                                                           controltype int(11) NOT NULL default '0',\r\n                                                           datatype varchar(64) NOT NULL default '',\r\n                                                           required tinyint(1) NOT NULL default '0',\r\n                                                           fieldlength int(11) NOT NULL default '0',\r\n                                                           weight int(11) NOT NULL default '0',\r\n                                                           fieldvalues mediumtext NOT NULL,\r\n                                                           defaultvalue varchar(100) NOT NULL default '',\r\n                                                           validation mediumtext NOT NULL,\r\n                                                           PRIMARY KEY (id),\r\n                                                           KEY weight (weight)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_fields')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_fields'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_fields'));
            set_time_limit(60);
            // Add notifications to new table
            set_time_limit(60);
            $hasNotifications = xhelpCreateNotifications();
            // Make all departments visible to all groups
            $hasDeptVisibility = xhelpCreateDepartmentVisibility();
            // Update staff permTimestamp
            $hStaff->updateAll('permTimestamp', time());
            set_time_limit(60);
            //Update xhelp_tickets table
            set_time_limit(60);
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY subject VARCHAR(255) NOT NULL default ''", $xoopsDB->prefix('xhelp_tickets')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_tickets'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_tickets'));
        case '0.75':
            set_time_limit(60);
            // Set default department
            $xoopsModuleConfig =& xhelpGetModuleConfig();
            if (isset($xoopsModuleConfig['xhelp_defaultDept']) && $xoopsModuleConfig['xhelp_defaultDept'] != 0) {
                $ret = xhelpSetMeta('default_department', $xoopsModuleConfig['xhelp_defaultDept']);
            } else {
                $hDepartments =& xhelpGetHandler('department');
                $depts =& $hDepartments->getObjects();
                $aDepts = array();
                foreach ($depts as $dpt) {
                    $aDepts[] = $dpt->getVar('id');
                }
                $ret = xhelpSetMeta("default_department", $aDepts[0]);
            }
            $qry = $xoopsDB->query(sprintf("ALTER TABLE %s DROP PRIMARY KEY", $xoopsDB->prefix('xhelp_ticket_submit_emails')));
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD PRIMARY KEY(ticketid, uid, email)", $xoopsDB->prefix('xhelp_ticket_submit_emails')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_ticket_submit_emails'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_ticket_submit_emails'));
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s MODIFY department int(11) NOT NULL default '0'", $xoopsDB->prefix('xhelp_jstaffdept')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_jstaffdept'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_jstaffdept'));
            echo "<li>" . _AM_XHELP_MSG_CHANGED_DEFAULT_DEPT . "</li>";
            // Add field to xhelp_saved_searches to determine if custom fields table is needed
            $ret = $ret && _runQuery(sprintf("ALTER TABLE %s ADD (hasCustFields int(11) NOT NULL default '0')", $xoopsDB->prefix('xhelp_saved_searches')), sprintf(_AM_XHELP_MSG_MODIFYTABLE, 'xhelp_saved_searches'), sprintf(_AM_XHELP_MSG_MODIFYTABLE_ERR, 'xhelp_saved_searches'));
            // Take existing saved searches and add 'query' field
            $hSavedSearch =& xhelpGetHandler('savedSearch');
            $savedSearches =& $hSavedSearch->getObjects();
            foreach ($savedSearches as $savedSearch) {
                set_time_limit(60);
                $crit =& unserialize($savedSearch->getVar('search'));
                if (is_object($crit)) {
                    $savedSearch->setVar('query', $crit->render());
                    if ($hSavedSearch->insert($savedSearch)) {
                        echo "<li>" . sprintf(_AM_XHELP_MSG_UPDATE_SEARCH, $savedSearch->getVar('id')) . "</li>";
                    } else {
                        echo "<li>" . sprintf(_AM_XHELP_MSG_UPDATE_SEARCH_ERR, $savedSearch->getVar('id')) . "</li>";
                    }
                }
            }
            unset($savedSearches);
            // Add ticket list table
            set_time_limit(60);
            $ret = $ret && _runQuery(sprintf("CREATE TABLE %s (id int(11) NOT NULL auto_increment,\r\n                                                           uid int(11) NOT NULL default '0',\r\n                                                           searchid int(11) NOT NULL default '0',\r\n                                                           weight int(11) NOT NULL default '0',\r\n                                                           PRIMARY KEY (id),\r\n                                                           KEY ticketList (uid, searchid)\r\n                                                          )ENGINE=MyISAM;", $xoopsDB->prefix('xhelp_ticket_lists')), sprintf(_AM_XHELP_MSG_ADDTABLE, 'xhelp_ticket_lists'), sprintf(_AM_XHELP_MSG_ADDTABLE_ERR, 'xhelp_ticket_lists'));
            // Add global ticket lists for staff members
            xhelpCreateDefaultTicketLists();
            set_time_limit(60);
            // Update xhelp_roles Admin record with new value (4095)
            $crit = new Criteria('tasks', 2047);
            $admin_roles =& $hRole->getObjects($crit);
            foreach ($admin_roles as $role) {
                $role->setVar('tasks', 4095);
                if ($hRole->insert($role)) {
                    echo "<li>" . sprintf(_AM_XHELP_MSG_UPDATE_ROLE, $role->getVar('name')) . "</li>";
                } else {
                    echo "<li>" . sprintf(_AM_XHELP_MSG_UPDATE_ROLE_ERR, $role->getVar('name')) . "</li>";
                }
            }
        case '0.77':
            // No schema changes for 0.78
        // No schema changes for 0.78
        case '0.78':
            echo "</ul>";
    }
    $newversion = round($xoopsModule->getVar('version') / 100, 2);
    //if successful, update xhelp_meta table with new ver
    if ($ret) {
        printf(_AM_XHELP_UPDATE_OK, $newversion);
        $ret = xhelpSetMeta('version', $newversion);
    } else {
        printf(_AM_XHELP_UPDATE_ERR, $newversion);
    }
    xhelpAdminFooter();
    xoops_cp_footer();
}
Example #17
0
function &_getTicketFields(&$ticket)
{
    $hFieldDept =& xhelpGetHandler('ticketFieldDepartment');
    $fields =& $hFieldDept->fieldsByDepartment($ticket->getVar('department'));
    $values =& $ticket->getCustFieldValues(true);
    foreach ($fields as $field) {
        $_arr = $field->toArray();
        $fieldname = $_arr['fieldname'];
        $_arr['value'] = $values[$fieldname]['value'];
        $_arr['fileid'] = $values[$fieldname]['fileid'];
        $_arr['filename'] = $values[$fieldname]['filename'];
        $ret[] = $_arr;
    }
    return $ret;
}
Example #18
0
 /**
  * Retrieve array of all staff with permission for current task
  */
 function getStaffByTask($task, $deptid = 0, $id_as_key = false)
 {
     $task = intval($task);
     if (isset($deptid)) {
         $deptid = intval($deptid);
     }
     // Get roles with $task value set
     $hRoles =& xhelpGetHandler('role');
     $roles =& $hRoles->getRolesByTask($task);
     $aRoles = array();
     foreach ($roles as $role) {
         $aRoles[$role->getVar('id')] = '';
     }
     // Get staff roles by dept
     $hStaffRole =& xhelpGetHandler('staffRole');
     $crit = new CriteriaCompo(new Criteria('deptid', $deptid));
     $crit->add(new Criteria('roleid', "(" . implode(array_keys($aRoles), ',') . ")", 'IN'));
     unset($aRoles);
     $staffRoles =& $hStaffRole->getObjects($crit);
     $aStaffID = array();
     foreach ($staffRoles as $sRole) {
         $aStaffID[$sRole->getVar('uid')] = '';
     }
     // Get staff objects
     $crit = new Criteria('uid', "(" . implode(array_keys($aStaffID), ',') . ")", 'IN');
     $hStaff =& xhelpGetHandler('staff');
     return $hStaff->getObjects($crit, $id_as_key);
 }
Example #19
0
 /**
  * Event Handler for 'delete_staff' event
  * @param xhelpStaff $staff Staff member being deleted
  * @return bool True on success, false on error
  * @access public
  */
 function delete_staff($staff)
 {
     $hTicket =& xhelpGetHandler('ticket');
     return $hTicket->updateAll('ownership', 0, new Criteria('ownership', $staff->getVar('uid')));
 }
Example #20
0
 /**
  * delete a ticket from the database
  *
  * @param object $obj reference to the {@link xhelpTicket} obj to delete
  * @param bool $force
  * @return bool FALSE if failed.
  * @access	public
  */
 function delete(&$obj, $force = false)
 {
     if (strcasecmp($this->classname, get_class($obj)) != 0) {
         return false;
     }
     // Remove all ticket responses first
     $hResponses =& xhelpGetHandler('responses');
     if (!$hResponses->deleteAll(new Criteria('ticketid', $obj->getVar('id')))) {
         return false;
     }
     // Remove all files associated with this ticket
     $hFiles =& xhelpGetHandler('file');
     if (!$hFiles->deleteAll(new Criteria('ticketid', $obj->getVar('id')))) {
         return false;
     }
     // Remove custom field values for this ticket
     $hFieldValues =& xhelpGetHandler('ticketValues');
     if (!$hFieldValues->deleteAll(new Criteria('ticketid', $obj->getVar('id')))) {
         return false;
     }
     $ret = parent::delete($obj, $force);
     return $ret;
 }
Example #21
0
 function inAllDepts($staffDepts)
 {
     $hDept =& xhelpGetHandler('department');
     $allDepts = $hDept->getCount();
     $numDepts = 0;
     foreach ($staffDepts as $dept) {
         $numDepts++;
     }
     if ($allDepts != $numDepts) {
         return false;
     }
     return true;
 }
Example #22
0
                $aDepts[] = $dpt->getVar('id');
            }
            if (isset($aDepts[0])) {
                xhelpSetMeta("default_department", $aDepts[0]);
            }
        } else {
            $message = _XHELP_MESSAGE_DEPT_DELETE_ERROR . $dept->getHtmlErrors();
        }
        redirect_header(XHELP_ADMIN_URL . "/department.php?op=manageDepartments", 3, $message);
    }
} elseif (isset($_REQUEST['deleteStaff'])) {
    if (isset($_REQUEST['uid'])) {
        $staffid = $_REQUEST['uid'];
        if (!isset($_POST['ok'])) {
            xoops_cp_header();
            echo $oAdminButton->renderButtons('manDept');
            xoops_confirm(array('deleteStaff' => 1, 'uid' => $staffid, 'ok' => 1), XHELP_BASE_URL . '/admin/delete.php', sprintf(_AM_XHELP_MSG_STAFF_DEL_CFRM, $staffid));
            xoops_cp_footer();
        } else {
            $hStaff =& xhelpGetHandler('staff');
            $staff =& $hStaff->getByUid($staffid);
            if ($hStaff->delete($staff)) {
                $_eventsrv->trigger('delete_staff', array(&$staff));
                $message = _XHELP_MESSAGE_STAFF_DELETE;
            } else {
                $message = _XHELP_MESSAGE_STAFF_DELETE_ERROR . $staff->getHtmlErrors();
            }
            redirect_header(XHELP_ADMIN_URL . "/staff.php?op=manageStaff", 3, $message);
        }
    }
}
Example #23
0
$oAdminButton->addTopLink(_MI_XHELP_MENU_CHECK_TABLES, XHELP_ADMIN_URL . "/upgrade.php?op=checkTables");
$oAdminButton->AddTopLink(_AM_XHELP_ADMIN_GOTOMODULE, XHELP_BASE_URL . "/index.php");
$oAdminButton->AddTopLink(_AM_XHELP_ADMIN_ABOUT, XHELP_ADMIN_URL . "/index.php?op=about");
$myts =& MyTextSanitizer::getInstance();
$imagearray = array('editimg' => "<img src='" . XHELP_IMAGE_URL . "/button_edit.png' alt='" . _AM_XHELP_ICO_EDIT . "' align='middle' />", 'deleteimg' => "<img src='" . XHELP_IMAGE_URL . "/button_delete.png' alt='" . _AM_XHELP_ICO_DELETE . "' align='middle' />", 'online' => "<img src='" . XHELP_IMAGE_URL . "/on.png' alt='" . _AM_XHELP_ICO_ONLINE . "' align='middle' />", 'offline' => "<img src='" . XHELP_IMAGE_URL . "/off.png' alt='" . _AM_XHELP_ICO_OFFLINE . "' align='middle' />");
// Overdue time
require_once XHELP_CLASS_PATH . '/session.php';
$_xhelpSession = new Session();
if (!($overdueTime = $_xhelpSession->get("xhelp_overdueTime"))) {
    $_xhelpSession->set("xhelp_overdueTime", $xoopsModuleConfig['xhelp_overdueTime']);
    $overdueTime = $_xhelpSession->get("xhelp_overdueTime");
}
if ($overdueTime != $xoopsModuleConfig['xhelp_overdueTime']) {
    $_xhelpSession->set("xhelp_overdueTime", $xoopsModuleConfig['xhelp_overdueTime']);
    // Set new value for overdueTime
    // Change overdueTime in all of tickets (OPEN & HOLD)
    $hTickets =& xhelpGetHandler('ticket');
    $crit = new Criteria('status', 2, '<>');
    $tickets =& $hTickets->getObjects($crit);
    $updatedTickets = array();
    foreach ($tickets as $ticket) {
        $ticket->setVar('overdueTime', $ticket->getVar('posted') + $xoopsModuleConfig['xhelp_overdueTime'] * 60 * 60);
        if (!$hTickets->insert($ticket, true)) {
            $updatedTickets[$ticket->getVar('id')] = false;
            // Not used anywhere
        } else {
            $updatedTickets[$ticket->getVar('id')] = true;
            // Not used anywhere
        }
    }
}
Example #24
0
function userviewall_display()
{
    global $xoopsOption, $xoopsTpl, $xoopsConfig, $xoopsUser, $xoopsLogger, $xoopsUserIsAdmin;
    global $xhelp_module_header, $sort, $order, $sort_order, $limit, $start, $state_opt, $state;
    $xoopsOption['template_main'] = 'xhelp_user_viewall.html';
    // Set template
    require XOOPS_ROOT_PATH . '/header.php';
    // Include the page header
    //Sanity Check: sort column valid
    $sort_columns = array('id' => 'DESC', 'priority' => 'DESC', 'elapsed' => 'ASC', 'lastupdate' => 'ASC', 'status' => 'ASC', 'subject' => 'ASC', 'department' => 'ASC', 'ownership' => 'ASC', 'uid' => 'ASC');
    $sort = array_key_exists($sort, $sort_columns) ? $sort : 'id';
    $order = @$_REQUEST['order'];
    $order = in_array(strtoupper($order), $sort_order) ? $order : $sort_columns[$sort];
    $uid = $xoopsUser->getVar('uid');
    $hDepartments =& xhelpGetHandler('department');
    $hTickets =& xhelpGetHandler('ticket');
    $hStaff =& xhelpGetHandler('staff');
    $dept = intval(isset($_REQUEST['dept']) ? $_REQUEST['dept'] : 0);
    $status = intval(isset($_REQUEST['status']) ? $_REQUEST['status'] : -1);
    $state = intval(isset($_REQUEST['state']) ? $_REQUEST['state'] : -1);
    $depts =& $hDepartments->getObjects(null, true);
    if ($limit == 0) {
        $limit = 10;
    } elseif ($limit == -1) {
        $limit = 0;
    }
    //Prepare Database Query and Querystring
    $crit = new CriteriaCompo(new Criteria('uid', $uid));
    $qs = array('op' => 'userViewAll', 'start' => $start, 'limit' => $limit);
    if ($dept) {
        $qs['dept'] = $dept;
        $crit->add(new Criteria('department', $dept, '=', 't'));
    }
    if ($status != -1) {
        $qs['status'] = $status;
        $crit->add(new Criteria('status', $status, '=', 't'));
    }
    if ($state != -1) {
        $qs['state'] = $state;
        $crit->add(new Criteria('state', $state, '=', 's'));
    }
    $crit->setLimit($limit);
    $crit->setStart($start);
    $crit->setSort($sort);
    $crit->setOrder($order);
    //Setup Column Sorting Vars
    $tpl_cols = array();
    foreach ($sort_columns as $col => $initsort) {
        $col_qs = array('sort' => $col);
        //Check if we need to sort by current column
        if ($sort == $col) {
            $col_qs['order'] = $order == $sort_order[0] ? $sort_order[1] : $sort_order[0];
            $col_sortby = true;
        } else {
            $col_qs['order'] = $initsort;
            $col_sortby = false;
        }
        $tpl_cols[$col] = array('url' => xhelpMakeURI(basename(__FILE__), array_merge($qs, $col_qs)), 'urltitle' => _XHELP_TEXT_SORT_TICKETS, 'sortby' => $col_sortby, 'sortdir' => strtolower($col_qs['order']));
    }
    $xoopsTpl->assign('xhelp_cols', $tpl_cols);
    $staffCount =& $hStaff->getObjects();
    if (count($staffCount) == 0) {
        $xoopsTpl->assign('xhelp_noStaff', true);
    }
    $userTickets =& $hTickets->getObjects($crit);
    foreach ($userTickets as $ticket) {
        $aUserTickets[] = array('id' => $ticket->getVar('id'), 'uid' => $ticket->getVar('uid'), 'subject' => xoops_substr($ticket->getVar('subject'), 0, 35), 'full_subject' => $ticket->getVar('subject'), 'status' => xhelpGetStatus($ticket->getVar('status')), 'department' => _safeDepartmentName($depts[$ticket->getVar('department')]), 'departmentid' => $ticket->getVar('department'), 'departmenturl' => xhelpMakeURI(basename(__FILE__), array('op' => 'userViewAll', 'dept' => $ticket->getVar('department'))), 'priority' => $ticket->getVar('priority'), 'posted' => $ticket->posted(), 'elapsed' => $ticket->elapsed());
    }
    $has_userTickets = count($userTickets) > 0;
    if ($has_userTickets) {
        $xoopsTpl->assign('xhelp_userTickets', $aUserTickets);
    } else {
        $xoopsTpl->assign('xhelp_userTickets', 0);
    }
    $javascript = "<script type=\"text/javascript\" src=\"" . XHELP_BASE_URL . "/include/functions.js\"></script>\r\n<script type=\"text/javascript\" src='" . XHELP_SCRIPT_URL . "/changeSelectedState.php?client'></script>\r\n<script type=\"text/javascript\">\r\n<!--\r\nfunction states_onchange()\r\n{\r\n    state = xoopsGetElementById('state');\r\n    var sH = new xhelpweblib(stateHandler);\r\n    sH.statusesbystate(state.value);\r\n}\r\n\r\nvar stateHandler = {\r\n    statusesbystate: function(result){\r\n        var statuses = gE('status');\r\n        xhelpFillSelect(statuses, result);\r\n    }\r\n}\r\n\r\nfunction window_onload()\r\n{\r\n    xhelpDOMAddEvent(xoopsGetElementById('state'), 'change', states_onchange, true);\r\n}\r\n\r\nwindow.setTimeout('window_onload()', 1500);\r\n//-->\r\n</script>";
    $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL);
    $xoopsTpl->assign('xhelp_has_userTickets', $has_userTickets);
    $xoopsTpl->assign('xhelp_viewAll', true);
    $xoopsTpl->assign('xhelp_priorities', array(5, 4, 3, 2, 1));
    $xoopsTpl->assign('xhelp_priorities_desc', array('5' => _XHELP_PRIORITY5, '4' => _XHELP_PRIORITY4, '3' => _XHELP_PRIORITY3, '2' => _XHELP_PRIORITY2, '1' => _XHELP_PRIORITY1));
    $xoopsTpl->assign('xhelp_imagePath', XHELP_IMAGE_URL . '/');
    $xoopsTpl->assign('xoops_module_header', $javascript . $xhelp_module_header);
    $xoopsTpl->assign('xhelp_limit_options', array(-1 => _XHELP_TEXT_SELECT_ALL, 10 => '10', 15 => '15', 20 => '20', 30 => '30'));
    $xoopsTpl->assign('xhelp_filter', array('department' => $dept, 'status' => $status, 'limit' => $limit, 'start' => $start, 'sort' => $sort, 'order' => $order, 'state' => $state));
    $xoopsTpl->append('xhelp_department_values', 0);
    $xoopsTpl->append('xhelp_department_options', _XHELP_TEXT_SELECT_ALL);
    //$depts = getVisibleDepartments($depts);
    $hMembership =& xhelpGetHandler('membership');
    $depts =& $hMembership->getVisibleDepartments($xoopsUser->getVar('uid'));
    foreach ($depts as $xhelp_id => $obj) {
        $xoopsTpl->append('xhelp_department_values', $xhelp_id);
        $xoopsTpl->append('xhelp_department_options', $obj->getVar('department'));
    }
    $hStatus =& xhelpGetHandler('status');
    $crit = new Criteria('', '');
    $crit->setSort('description');
    $crit->setOrder('ASC');
    $statuses =& $hStatus->getObjects($crit);
    $xoopsTpl->append('xhelp_status_options', _XHELP_TEXT_SELECT_ALL);
    $xoopsTpl->append('xhelp_status_values', -1);
    foreach ($statuses as $status) {
        $xoopsTpl->append('xhelp_status_options', $status->getVar('description'));
        $xoopsTpl->append('xhelp_status_values', $status->getVar('id'));
    }
    $xoopsTpl->assign('xhelp_department_current', $dept);
    $xoopsTpl->assign('xhelp_status_current', $status);
    $xoopsTpl->assign('xhelp_state_options', array_keys($state_opt));
    $xoopsTpl->assign('xhelp_state_values', array_values($state_opt));
    require XOOPS_ROOT_PATH . '/footer.php';
}
Example #25
0
 function _saveAttachments($msg, $ticketid, $responseid = 0)
 {
     global $xoopsModuleConfig;
     $attachments = $msg->getAttachments();
     $dir = XOOPS_UPLOAD_PATH . '/xhelp';
     $prefix = $responseid != 0 ? $ticketid . '_' . $responseid . '_' : $ticketid . '_';
     $hMime =& xhelpGetHandler('mimetype');
     $allowed_mimetypes = $hMime->getArray();
     if (!is_dir($dir)) {
         mkdir($dir, 0757);
     }
     $dir .= '/';
     if ($xoopsModuleConfig['xhelp_allowUpload']) {
         $hFile =& xhelpGetHandler('file');
         foreach ($attachments as $attach) {
             $validators = array();
             //Create Temporary File
             $fname = $prefix . $attach['filename'];
             $fp = fopen($dir . $fname, 'w');
             fwrite($fp, $attach['content']);
             fclose($fp);
             $validators[] = new ValidateMimeType($dir . $fname, $attach['content-type'], $allowed_mimetypes);
             $validators[] = new ValidateFileSize($dir . $fname, $xoopsModuleConfig['xhelp_uploadSize']);
             $validators[] = new ValidateImageSize($dir . $fname, $xoopsModuleConfig['xhelp_uploadWidth'], $xoopsModuleConfig['xhelp_uploadHeight']);
             if (!xhelpCheckRules($validators, $errors)) {
                 //Remove the file
                 $this->_addAttachmentError($errors, $msg, $fname);
                 unlink($dir . $fname);
             } else {
                 //Add attachment to ticket
                 $file =& $hFile->create();
                 $file->setVar('filename', $fname);
                 $file->setVar('ticketid', $ticketid);
                 $file->setVar('mimetype', $attach['content-type']);
                 $file->setVar('responseid', $responseid);
                 $hFile->insert($file, true);
             }
         }
     } else {
         $this->_setError(_XHELP_MESSAGE_UPLOAD_ALLOWED_ERR);
         // Error: file uploading is disabled
     }
 }
Example #26
0
                 redirect_header(XHELP_BASE_URL . "/addTicket.php", 5, $message);
             }
         }
     }
 }
 if ($hTicket->insert($ticket)) {
     $ticket->addSubmitter($xoopsUser->getVar('email'), $xoopsUser->getVar('uid'));
     if (count($aUploadFiles) > 0) {
         // Has uploaded files?
         foreach ($aUploadFiles as $key => $aFile) {
             $file = $ticket->storeUpload($key, null, $allowed_mimetypes);
             $_eventsrv->trigger('new_file', array(&$ticket, &$file));
         }
     }
     // Add custom field values to db
     $hTicketValues = xhelpGetHandler('ticketValues');
     $ticketValues = $hTicketValues->create();
     foreach ($aFields as $field) {
         $fieldname = $field['fieldname'];
         $fieldtype = $field['controltype'];
         if ($fieldtype == XHELP_CONTROL_FILE) {
             // If custom field was a file upload
             if ($xoopsModuleConfig['xhelp_allowUpload']) {
                 // If uploading is allowed
                 if (is_uploaded_file($_FILES[$fieldname]['tmp_name'])) {
                     if (!($ret = $ticket->checkUpload($fieldname, $allowed_mimetypes, $errors))) {
                         $errorstxt = implode('<br />', $errors);
                         $message = sprintf(_XHELP_MESSAGE_FILE_ERROR, $errorstxt);
                         redirect_header(XHELP_BASE_URL . "/addTicket.php", 5, $message);
                     }
                     if ($file = $ticket->storeUpload($fieldname, -1, $allowed_mimetypes)) {
Example #27
0
 /**
  * Add Log Events for 'batch_dept' event
  * @param array $tickets Array of xhelpTicket objects
  * @param xhelpDepartment $dept New department for tickets
  * @return bool True on success, false on error
  * @access public
  */
 function batch_dept($tickets, $dept)
 {
     global $xoopsUser;
     $hDept =& xhelpGetHandler('department');
     $deptObj =& $hDept->get($dept);
     foreach ($tickets as $ticket) {
         $logMessage =& $this->_hLog->create();
         $logMessage->setVar('uid', $xoopsUser->getVar('uid'));
         $logMessage->setVar('ticketid', $ticket->getVar('id'));
         $logMessage->setVar('lastUpdated', time());
         $logMessage->setVar('action', sprintf(_XHELP_LOG_SETDEPT, $deptObj->getVar('department')));
         $this->_hLog->insert($logMessage);
         unset($logMessage);
     }
     return true;
 }
Example #28
0
 function createStaffGlobalLists($uid)
 {
     $hSavedSearches =& xhelpGetHandler('savedSearch');
     $uid = intval($uid);
     $crit = new Criteria('uid', XHELP_GLOBAL_UID);
     $crit->setSort('id');
     $crit->setOrder('ASC');
     $globalSearches =& $hSavedSearches->getObjects($crit, true);
     $i = 1;
     foreach ($globalSearches as $search) {
         $list =& $this->create();
         $list->setVar('uid', $uid);
         $list->setVar('searchid', $search->getVar('id'));
         $list->setVar('weight', $i);
         $ret = $this->insert($list, true);
         $i++;
     }
     return $ret;
 }
Example #29
0
function b_xhelp_mainactions_show($options)
{
    global $xoopsUser, $xhelp_isStaff;
    // @todo - use the constant here if possible instead of the raw string
    $dirname = 'xhelp';
    $block['linkPath'] = XHELP_BASE_URL . '/';
    $block['imagePath'] = XHELP_IMAGE_URL . '/';
    $block['menustyle'] = $options[0];
    $block['showicon'] = !$block['menustyle'] && $options[1];
    $block['startitem'] = !$block['menustyle'] ? '<li>' : '';
    $block['enditem'] = !$block['menustyle'] ? '</li>' : '';
    $block['startblock'] = !$block['menustyle'] ? '<ul>' : '<table cellspacing="0"><tr><td id="usermenu">';
    $block['endblock'] = !$block['menustyle'] ? '</ul>' : '</td></tr></table>';
    $block['savedSearches'] = false;
    $block['items'][0] = array('link' => 'anon_addTicket.php', 'image' => 'addTicket.png', 'text' => _XHELP_MENU_LOG_TICKET);
    if ($xoopsUser) {
        $block['items'][0] = array('link' => 'index.php', 'image' => 'main.png', 'text' => _XHELP_MENU_MAIN);
        $block['items'][1] = array('link' => 'addTicket.php', 'image' => 'addTicket.png', 'text' => _XHELP_MENU_LOG_TICKET);
        $block['items'][2] = array('link' => 'index.php?viewAllTickets=1&op=userViewAll', 'image' => 'ticket.png', 'text' => _XHELP_MENU_ALL_TICKETS);
        $hStaff =& xhelpGetHandler('staff');
        if ($xhelp_staff =& $hStaff->getByUid($xoopsUser->getVar('uid'))) {
            $block['whoami'] = 'staff';
            $block['items'][3] = array('link' => 'search.php', 'image' => 'search2.png', 'text' => _XHELP_MENU_SEARCH);
            $block['items'][4] = array('link' => 'profile.php', 'image' => 'profile.png', 'text' => _XHELP_MENU_MY_PROFILE);
            $block['items'][2] = array('link' => 'index.php?viewAllTickets=1&op=staffViewAll', 'image' => 'ticket.png', 'text' => _XHELP_MENU_ALL_TICKETS);
            $hSavedSearch =& xhelpGetHandler('savedSearch');
            $savedSearches =& $hSavedSearch->getByUid($xoopsUser->getVar('uid'));
            $aSavedSearches = array();
            foreach ($savedSearches as $sSearch) {
                $aSavedSearches[$sSearch->getVar('id')] = array('id' => $sSearch->getVar('id'), 'name' => $sSearch->getVar('name'), 'search' => $sSearch->getVar('search'), 'pagenav_vars' => $sSearch->getVar('pagenav_vars'));
            }
            $block['savedSearches'] = count($aSavedSearches) < 1 ? false : $aSavedSearches;
        }
    }
    return $block;
}
Example #30
0
function xhelpCreateDepartmentVisibility()
{
    $hDepartments =& xhelpGetHandler('department');
    $hGroups =& xoops_gethandler('group');
    $hGroupPerm =& xoops_gethandler('groupperm');
    $xoopsModule =& xhelpGetModule();
    $module_id = $xoopsModule->getVar('mid');
    // Get array of all departments
    $departments =& $hDepartments->getObjects(null, true);
    // Get array of groups
    $groups =& $hGroups->getObjects(null, true);
    $aGroups = array();
    foreach ($groups as $group_id => $group) {
        $aGroups[$group_id] = $group->getVar('name');
    }
    foreach ($departments as $dept) {
        $deptID = $dept->getVar('id');
        // Remove old group permissions
        $crit = new CriteriaCompo(new Criteria('gperm_modid', $module_id));
        $crit->add(new Criteria('gperm_itemid', $deptID));
        $crit->add(new Criteria('gperm_name', _XHELP_GROUP_PERM_DEPT));
        $hGroupPerm->deleteAll($crit);
        foreach ($aGroups as $group => $group_name) {
            // Add new group permissions
            $hGroupPerm->addRight(_XHELP_GROUP_PERM_DEPT, $deptID, $group, $module_id);
        }
        // Todo: Possibly add text saying, "Visibility for Department x set"
    }
    return true;
}