Exemple #1
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();
}
Exemple #2
0
function xoops_module_install_xhelp(&$module)
{
    $myTopics = updateTopics(true);
    $hasRoles = xhelpCreateRoles();
    $hasStatuses = xhelpCreateStatuses();
    $hasNotifications = xhelpCreateNotifications();
    $hasTicketLists = xhelpCreateDefaultTicketLists();
    return true;
}