コード例 #1
0
ファイル: status.php プロジェクト: trabisdementia/xuups
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();
}
コード例 #2
0
ファイル: department.php プロジェクト: trabisdementia/xuups
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&amp;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&amp;deptid={$deptID}&amp;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&amp;uid=" . $uid . "'><img src='" . XOOPS_URL . "/modules/xhelp/images/button_edit.png' title='" . _AM_XHELP_TEXT_EDIT . "' name='editStaff' /></a>&nbsp;\r\n                          <a href='" . XHELP_ADMIN_URL . "/department.php?op=deleteStaffDept&amp;uid=" . $uid . "&amp;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&amp;setstate=0&amp;id=' . $server->getVar('id');
                    $activ_img = $imagearray['online'];
                    $activ_title = _AM_XHELP_MESSAGE_DEACTIVATE;
                } else {
                    $activ_link = '".XHELP_ADMIN_URL."/department.php?op=activateMailbox&amp;setstate=1&amp;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&amp;id=' . $server->GetVar('id') . '">' . $imagearray['editimg'] . '</a>
                        <a href="' . XHELP_ADMIN_URL . '/department.php?op=DeleteDepartmentServer&amp;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();
    }
}
コード例 #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);
        }
    }
}