function editDepartment() { $_xhelpSession = Session::singleton(); global $imagearray, $xoopsModule, $oAdminButton, $limit, $start, $xoopsModuleConfig; $module_id = $xoopsModule->getVar('mid'); $displayName =& $xoopsModuleConfig['xhelp_displayName']; // Determines if username or real name is displayed $_xhelpSession->set("xhelp_return_page", substr(strstr($_SERVER['REQUEST_URI'], 'admin/'), 6)); if (isset($_REQUEST["deptid"])) { $deptID = $_REQUEST['deptid']; } else { redirect_header(XHELP_ADMIN_URL . "/department.php?op=manageDepartments", 3, _AM_XHELP_MSG_NO_DEPTID); } $hDepartments =& xhelpGetHandler('department'); $hGroups =& xoops_gethandler('group'); $hGroupPerm =& xoops_gethandler('groupperm'); if (isset($_POST['updateDept'])) { $groups = isset($_POST['groups']) ? $_POST['groups'] : array(); $hasErrors = false; //Department Name supplied? if (trim($_POST['newDept']) == '') { $hasErrors = true; $errors['newDept'][] = _AM_XHELP_MESSAGE_NO_DEPT; } else { //Department Name unique? $crit = new CriteriaCompo(new Criteria('department', $_POST['newDept'])); $crit->add(new Criteria('id', $deptID, '!=')); if ($existingDepts = $hDepartments->getCount($crit)) { $hasErrors = true; $errors['newDept'][] = _XHELP_MESSAGE_DEPT_EXISTS; } } if ($hasErrors) { $session =& Session::singleton(); //Store existing dept info in session, reload addition page $aDept = array(); $aDept['newDept'] = $_POST['newDept']; $aDept['groups'] = $groups; $session->set("xhelp_editDepartment_{$deptID}", $aDept); $session->set("xhelp_editDepartmentErrors_{$deptID}", $errors); header('Location: ' . xhelpMakeURI(XHELP_ADMIN_URL . '/department.php', array('op' => 'editDepartment', 'deptid' => $deptID), false)); exit; } $dept =& $hDepartments->get($deptID); $oldDept = $dept; $groups = $_POST['groups']; // Need to remove old group permissions first $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 ($groups as $group) { // Add new group permissions $hGroupPerm->addRight(_XHELP_GROUP_PERM_DEPT, $deptID, $group, $module_id); } $dept->setVar('department', $_POST['newDept']); if ($hDepartments->insert($dept)) { $message = _XHELP_MESSAGE_UPDATE_DEPT; // Update default dept if (isset($_POST['defaultDept']) && $_POST['defaultDept'] == 1) { xhelpSetMeta("default_department", $dept->getVar('id')); } else { $depts =& $hDepartments->getObjects(); $aDepts = array(); foreach ($depts as $dpt) { $aDepts[] = $dpt->getVar('id'); } xhelpSetMeta("default_department", $aDepts[0]); } // Edit configoption for department $hConfigOption =& xoops_gethandler('configoption'); $crit = new CriteriaCompo(new Criteria('confop_name', $oldDept->getVar('department'))); $crit->add(new Criteria('confop_value', $oldDept->getVar('id'))); $confOption =& $hConfigOption->getObjects($crit); if (count($confOption) > 0) { $confOption[0]->setVar('confop_name', $dept->getVar('department')); if (!$hConfigOption->insert($confOption[0])) { redirect_header(XHELP_ADMIN_URL . "/department.php?op=manageDepartments", 3, _AM_XHELP_MSG_UPDATE_CONFIG_ERR); } } _clearEditSessionVars($deptID); header("Location: " . XHELP_ADMIN_URL . "/department.php?op=manageDepartments"); } else { $message = _XHELP_MESSAGE_UPDATE_DEPT_ERROR . $dept->getHtmlErrors(); redirect_header(XHELP_ADMIN_URL . "/department.php?op=manageDepartments", 3, $message); } } else { xoops_cp_header(); echo $oAdminButton->renderButtons('manDept'); $dept =& $hDepartments->get($deptID); $session =& Session::singleton(); $sess_dept = $session->get("xhelp_editDepartment_{$deptID}"); $sess_errors = $session->get("xhelp_editDepartmentErrors_{$deptID}"); //Display any form errors if (!$sess_errors === false) { xhelpRenderErrors($sess_errors, xhelpMakeURI(XHELP_ADMIN_URL . '/department.php', array('op' => 'clearEditSession', 'deptid' => $deptID))); } // Get list of groups with permission $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)); $group_perms =& $hGroupPerm->getObjects($crit); $aPerms = array(); // Put group_perms in usable format foreach ($group_perms as $perm) { $aPerms[$perm->getVar('gperm_groupid')] = $perm->getVar('gperm_groupid'); } if (!$sess_dept === false) { $fld_newDept = $sess_dept['newDept']; $fld_groups = $sess_dept['groups']; } else { $fld_newDept = $dept->getVar('department'); $fld_groups = $aPerms; } // Get list of all groups $crit = new Criteria('', ''); $crit->setSort('name'); $crit->setOrder('ASC'); $groups =& $hGroups->getObjects($crit, true); $aGroups = array(); foreach ($groups as $group_id => $group) { $aGroups[$group_id] = $group->getVar('name'); } asort($aGroups); // Set groups in alphabetical order echo '<script type="text/javascript" src="' . XOOPS_URL . '/modules/xhelp/include/functions.js"></script>'; $form = new xhelpForm(_AM_XHELP_EDIT_DEPARTMENT, 'edit_dept', xhelpMakeURI(XHELP_ADMIN_URL . '/department.php', array('op' => 'editDepartment', 'deptid' => $deptID))); $dept_name = new XoopsFormText(_AM_XHELP_TEXT_EDIT_DEPT, 'newDept', 20, 35, $fld_newDept); $group_select = new XoopsFormSelect(_AM_XHELP_TEXT_EDIT_DEPT_PERMS, 'groups', $fld_groups, 6, true); $group_select->addOptionArray($aGroups); $defaultDeptID = xhelpGetMeta("default_department"); $defaultDept = new xhelpFormCheckbox(_AM_XHELP_TEXT_DEFAULT_DEPT, 'defaultDept', $defaultDeptID == $deptID ? 1 : 0, 'defaultDept'); $defaultDept->addOption(1, ""); $btn_tray = new XoopsFormElementTray(''); $btn_tray->addElement(new XoopsFormButton('', 'updateDept', _AM_XHELP_BUTTON_SUBMIT, 'submit')); $form->addElement($dept_name); $form->addElement($group_select); $form->addElement($defaultDept); $form->addElement($btn_tray); $form->setLabelWidth('20%'); echo $form->render(); // Get dept staff members $hMembership =& xhelpGetHandler('membership'); $hMember =& xoops_gethandler('member'); $hStaffRole =& xhelpGetHandler('staffRole'); $hRole =& xhelpGetHandler('role'); $staff = $hMembership->membershipByDept($deptID, $limit, $start); $crit = new Criteria('j.department', $deptID); $staffCount =& $hMembership->getCount($crit); $roles =& $hRole->getObjects(null, true); echo "<form action='" . XHELP_ADMIN_URL . "/department.php?op=deleteStaffDept&deptid=" . $deptID . "' method='post'>"; echo "<table width='100%' cellspacing='1' class='outer'>\r\n <tr><th colspan='" . (3 + count($roles)) . "'><label>" . _AM_XHELP_MANAGE_STAFF . "</label></th></tr>"; if ($staffCount > 0) { $aStaff = array(); foreach ($staff as $stf) { $aStaff[$stf->getVar('uid')] = $stf->getVar('uid'); // Get array of staff uid } // Get user list $crit = new Criteria('uid', "(" . implode($aStaff, ',') . ")", "IN"); //$members =& $hMember->getUserList($crit); $members =& xhelpGetUsers($crit, $displayName); // Get staff roles $crit = new CriteriaCompo(new Criteria('uid', "(" . implode($aStaff, ',') . ")", "IN")); $crit->add(new Criteria('deptid', $deptID)); $staffRoles =& $hStaffRole->getObjects($crit); unset($aStaff); $staffInfo = array(); foreach ($staff as $stf) { $staff_uid = $stf->getVar('uid'); $staffInfo[$staff_uid]['uname'] = $members[$staff_uid]; $aRoles = array(); foreach ($staffRoles as $role) { $role_id = $role->getVar('roleid'); if ($role->getVar('uid') == $staff_uid) { $aRoles[$role_id] = $roles[$role_id]->getVar('name'); } $staffInfo[$staff_uid]['roles'] = implode($aRoles, ', '); } } $nav = new XoopsPageNav($staffCount, $limit, $start, 'start', "op=editDepartment&deptid={$deptID}&limit={$limit}"); echo "<tr class='head'><td rowspan='2'>" . _AM_XHELP_TEXT_ID . "</td><td rowspan='2'>" . _AM_XHELP_TEXT_USER . "</td><td colspan='" . count($roles) . "'>" . _AM_XHELP_TEXT_ROLES . "</td><td rowspan='2'>" . _AM_XHELP_TEXT_ACTIONS . "</td></tr>"; echo "<tr class='head'>"; foreach ($roles as $thisrole) { echo "<td>" . $thisrole->getVar('name') . "</td>"; } echo "</tr>"; foreach ($staffInfo as $uid => $staff) { echo "<tr class='even'>\r\n <td><input type='checkbox' name='staff[]' value='" . $uid . "' />" . $uid . "</td>\r\n <td>" . $staff['uname'] . "</td>"; foreach ($roles as $thisrole) { echo "<td><img src='" . XHELP_BASE_URL . "/images/"; echo in_array($thisrole->getVar('name'), explode(', ', $staff['roles'])) ? "on.png" : "off.png"; echo "' /></td>"; } echo " <td>\r\n <a href='" . XHELP_ADMIN_URL . "/staff.php?op=editStaff&uid=" . $uid . "'><img src='" . XOOPS_URL . "/modules/xhelp/images/button_edit.png' title='" . _AM_XHELP_TEXT_EDIT . "' name='editStaff' /></a> \r\n <a href='" . XHELP_ADMIN_URL . "/department.php?op=deleteStaffDept&uid=" . $uid . "&deptid=" . $deptID . "'><img src='" . XOOPS_URL . "/modules/xhelp/images/button_delete.png' title='" . _AM_XHELP_TEXT_DELETE_STAFF_DEPT . "' name='deleteStaffDept' /></a>\r\n </td>\r\n </tr>"; } echo "<tr>\r\n <td class='foot' colspan='" . (3 + count($roles)) . "'>\r\n <input type='checkbox' name='checkallRoles' value='0' onclick='selectAll(this.form,\"staff[]\",this.checked);' />\r\n <input type='submit' name='deleteStaff' id='deleteStaff' value='" . _AM_XHELP_BUTTON_DELETE . "' />\r\n </td>\r\n </tr>"; echo "</table></form>"; echo "<div id='staff_nav'>" . $nav->renderNav() . "</div>"; } else { echo "</table></form>"; } //now do the list of servers $hDeptServers =& xhelpGetHandler('departmentMailBox'); $deptServers =& $hDeptServers->getByDepartment($deptID); //iterate if (count($deptServers) > 0) { echo "<br /><table width='100%' cellspacing='1' class='outer'>\r\n <tr>\r\n <th colspan='5'><label>" . _AM_XHELP_DEPARTMENT_SERVERS . "</label></th>\r\n </tr>\r\n <tr>\r\n <td class='head' width='20%'><label>" . _AM_XHELP_DEPARTMENT_SERVERS_EMAIL . "</label></td>\r\n <td class='head'><label>" . _AM_XHELP_DEPARTMENT_SERVERS_TYPE . "</label></td>\r\n <td class='head'><label>" . _AM_XHELP_DEPARTMENT_SERVERS_SERVERNAME . "</label></td>\r\n <td class='head'><label>" . _AM_XHELP_DEPARTMENT_SERVERS_PORT . "</label></td>\r\n <td class='head'><label>" . _AM_XHELP_DEPARTMENT_SERVERS_ACTION . "</label></td>\r\n </tr>"; $i = 0; foreach ($deptServers as $server) { if ($server->getVar('active')) { $activ_link = '".XHELP_ADMIN_URL."/department.php?op=activateMailbox&setstate=0&id=' . $server->getVar('id'); $activ_img = $imagearray['online']; $activ_title = _AM_XHELP_MESSAGE_DEACTIVATE; } else { $activ_link = '".XHELP_ADMIN_URL."/department.php?op=activateMailbox&setstate=1&id=' . $server->getVar('id'); $activ_img = $imagearray['offline']; $activ_title = _AM_XHELP_MESSAGE_ACTIVATE; } echo '<tr class="even"> <td>' . $server->getVar('emailaddress') . '</td> <td>' . xhelpGetMBoxType($server->getVar('mboxtype')) . '</td> <td>' . $server->getVar('server') . '</td> <td>' . $server->getVar('serverport') . '</td> <td> <a href="' . $activ_link . '" title="' . $activ_title . '">' . $activ_img . '</a> <a href="' . XHELP_ADMIN_URL . '/department.php?op=EditDepartmentServer&id=' . $server->GetVar('id') . '">' . $imagearray['editimg'] . '</a> <a href="' . XHELP_ADMIN_URL . '/department.php?op=DeleteDepartmentServer&id=' . $server->GetVar('id') . '">' . $imagearray['deleteimg'] . '</a> </td> </tr>'; } echo '</table>'; } //finally add Mailbox form echo "<br /><br />"; $formElements = array('type_select', 'server_text', 'port_text', 'username_text', 'pass_text', 'priority_radio', 'email_text', 'btn_tray'); $form = new xhelpForm(_AM_XHELP_DEPARTMENT_ADD_SERVER, 'add_server', xhelpMakeURI(XHELP_ADMIN_URL . '/department.php', array('op' => 'AddDepartmentServer', 'id' => $deptID))); $type_select = new XoopsFormSelect(_AM_XHELP_DEPARTMENT_SERVERS_TYPE, 'mboxtype'); $type_select->setExtra("id='mboxtype'"); $type_select->addOption(_XHELP_MAILBOXTYPE_POP3, _AM_XHELP_MBOX_POP3); $server_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVERS_SERVERNAME, 'server', 40, 50); $server_text->setExtra("id='txtServer'"); $port_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVERS_PORT, 'port', 5, 5, "110"); $port_text->setExtra("id='txtPort'"); $username_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVER_USERNAME, 'username', 25, 50); $username_text->setExtra("id='txtUsername'"); $pass_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVER_PASSWORD, 'password', 25, 50); $pass_text->setExtra("id='txtPassword'"); $priority_radio = new xhelpFormRadio(_AM_XHELP_DEPARTMENT_SERVERS_PRIORITY, 'priority', XHELP_DEFAULT_PRIORITY); $priority_array = array('1' => "<label for='priority1'><img src='" . XHELP_IMAGE_URL . "/priority1.png' title='" . xhelpGetPriority(1) . "' alt='priority1' /></label>", '2' => "<label for='priority2'><img src='" . XHELP_IMAGE_URL . "/priority2.png' title='" . xhelpGetPriority(2) . "' alt='priority2' /></label>", '3' => "<label for='priority3'><img src='" . XHELP_IMAGE_URL . "/priority3.png' title='" . xhelpGetPriority(3) . "' alt='priority3' /></label>", '4' => "<label for='priority4'><img src='" . XHELP_IMAGE_URL . "/priority4.png' title='" . xhelpGetPriority(4) . "' alt='priority4' /></label>", '5' => "<label for='priority5'><img src='" . XHELP_IMAGE_URL . "/priority5.png' title='" . xhelpGetPriority(5) . "' alt='priority5' /></label>"); $priority_radio->addOptionArray($priority_array); $email_text = new XoopsFormText(_AM_XHELP_DEPARTMENT_SERVER_EMAILADDRESS, 'emailaddress', 50, 255); $email_text->setExtra("id='txtEmailaddress'"); $btn_tray = new XoopsFormElementTray(''); $test_button = new XoopsFormButton('', 'email_test', _AM_XHELP_BUTTON_TEST, 'button'); $test_button->setExtra("id='test'"); $submit_button = new XoopsFormButton('', 'updateDept2', _AM_XHELP_BUTTON_SUBMIT, 'submit'); $cancel2_button = new XoopsFormButton('', 'cancel2', _AM_XHELP_BUTTON_CANCEL, 'button'); $cancel2_button->setExtra("onclick='history.go(-1)'"); $btn_tray->addElement($test_button); $btn_tray->addElement($submit_button); $btn_tray->addElement($cancel2_button); $form->setLabelWidth('20%'); foreach ($formElements as $element) { $form->addElement(${$element}); } echo $form->render(); echo "<script type=\"text/javascript\" language=\"javascript\">\r\n <!--\r\n function xhelpEmailTest()\r\n {\r\n pop = openWithSelfMain(\"\", \"email_test\", 250, 150);\r\n frm = xoopsGetElementById(\"add_server\");\r\n newaction = \"department.php?op=testMailbox\";\r\n oldaction = frm.action;\r\n frm.action = newaction;\r\n frm.target = \"email_test\";\r\n frm.submit();\r\n frm.action = oldaction;\r\n frm.target = \"main\";\r\n\r\n }\r\n\r\n xhelpDOMAddEvent(xoopsGetElementById(\"email_test\"), \"click\", xhelpEmailTest, false);\r\n\r\n //-->\r\n </script>"; xhelpAdminFooter(); xoops_cp_footer(); } }
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&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 \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 \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&statusid=" . $status->getVar('id') . "'><img src='" . XHELP_IMAGE_URL . "/button_edit.png' title='" . _AM_XHELP_TEXT_EDIT . "' name='editStatus' /></a> \r\n <a href='status.php?op=deleteStatus&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(); }