require_once DP_BASE_DIR . '/includes/db_adodb.php'; require_once DP_BASE_DIR . '/includes/db_connect.php'; // Required here as we may either be an upgrade, or an install. $dbprefix = dPgetConfig('dbprefix', ''); // Now update the GACL class information. require_once DP_BASE_DIR . '/classes/permissions.class.php'; dPmsg('Creating new Permissions objects'); $perms = new dPacl(); // First, create the basic ACL sections. $perms->add_object_section('System', 'system', 1, 0, 'aco'); $perms->add_object_section('Application', 'application', 2, 0, 'aco'); $perms->add_object_section('Users', 'user', 1, 0, 'aro'); $perms->add_object_section('System', 'sys', 1, 0, 'axo'); $perms->add_object_section('Application', 'app', 2, 0, 'axo'); // Create the permissions in the ACO sections. $perms->add_object('system', 'Login', 'login', 1, 0, 'aco'); $perms->add_object('application', 'Access', 'access', 1, 0, 'aco'); $perms->add_object('application', 'View', 'view', 2, 0, 'aco'); $perms->add_object('application', 'Add', 'add', 3, 0, 'aco'); $perms->add_object('application', 'Edit', 'edit', 4, 0, 'aco'); $perms->add_object('application', 'Delete', 'delete', 5, 0, 'aco'); // Now create the groups we need. $role = $perms->add_group('role', 'Roles', 0, 'aro'); $admin_role = $perms->add_group('admin', 'Administrator', $role, 'aro'); $anon_role = $perms->add_group('anon', 'Anonymous', $role, 'aro'); $guest_role = $perms->add_group('guest', 'Guest', $role, 'aro'); $worker_role = $perms->add_group('normal', 'Project worker', $role, 'aro'); $mod = $perms->add_group('mod', 'Modules', 0, 'axo'); $all_mods = $perms->add_group('all', 'All Modules', $mod, 'axo'); $admin_mods = $perms->add_group('admin', 'Admin Modules', $mod, 'axo'); $non_admin_mods = $perms->add_group('non_admin', 'Non-Admin Modules', $mod, 'axo');
/** * DEVELOPERS PLEASE NOTE: * * For the new upgrader/installer to work, this code must be structured * correctly. In general if there is a difference between the from * version and the to version, then all updates should be performed. * If the $last_udpated is set, then a partial update is required as this * is a CVS update. Make sure you create a new case block for any updates * that you require, and set $latest_update to the date of the change. * * Each case statement should fall through to the next, so that the * complete update is run if the last_updated is not set. * * FURTHER NOTE: As of 2.1, individual upgrade*.php files are deprecated * as they are not necessary. ALL UPDATE CODE needs to be in upgrade_latest.php. * The individual SQL files are still required, however. */ function dPupgrade($from_version, $to_version, $last_updated) { $latest_update = '20080728'; // Set to the latest upgrade date. if (empty($last_updated) || empty($from_version)) { $last_updated = '00000000'; } $perms = new dPacl(); // Place the upgrade code here, depending on the last_updated date. // DO NOT REMOVE PREVIOUS VERSION CODE!!! switch ($last_updated) { case '00000000': $sql = 'SELECT project_id, project_departments, project_contacts FROM projects'; $projects = db_loadList($sql); //split out related departments and store them seperatly. $sql = 'DELETE FROM project_departments'; db_exec($sql); //split out related contacts and store them seperatly. $sql = 'DELETE FROM project_contacts'; db_exec($sql); foreach ($projects as $project) { $p_id = $project['project_id'] ? $project['project_id'] : '0'; $departments = explode(',', $project['project_departments']); foreach ($departments as $department) { $sql = 'INSERT INTO project_departments (project_id, department_id) values (' . $p_id . ', ' . $department . ')'; if ($p_id && $department) { db_exec($sql); } } $contacts = explode(',', $project['project_contacts']); foreach ($contacts as $contact) { $sql = 'INSERT INTO project_contacts (project_id, contact_id) values (' . $p_id . ', ' . $contact . ')'; if ($p_id && $contact) { db_exec($sql); } } } /** * This segment will extract all the task/department and task/contact relational info and populate the task_departments and task_contacts tables. **/ $sql = 'SELECT task_id, task_departments, task_contacts FROM tasks'; $tasks = db_loadList($sql); //split out related departments and store them seperatly. $sql = 'DELETE FROM task_departments'; db_exec($sql); //split out related contacts and store them seperatly. $sql = 'DELETE FROM task_contacts'; db_exec($sql); foreach ($tasks as $task) { $departments = explode(',', $task['task_departments']); foreach ($departments as $department) { if ($department) { $sql = 'INSERT INTO task_departments (task_id, department_id) values (' . $task['task_id'] . ', ' . $department . ')'; db_exec($sql); } } $contacts = explode(',', $task['task_contacts']); foreach ($contacts as $contact) { if ($contact) { $sql = 'INSERT INTO task_contacts (task_id, contact_id) values (' . $task['task_id'] . ', ' . $contact . ')'; db_exec($sql); } } } $sql = 'ALTER TABLE `projects` ADD `project_active` TINYINT(4) DEFAULT 1'; db_exec($sql); if (strcmp($from_version, '2') < 0) { include DP_BASE_DIR . '/db/upgrade_contacts.php'; } include DP_BASE_DIR . '/db/upgrade_permissions.php'; // Fallthrough // Fallthrough case '20050314': // Add the permissions for task_log dPmsg('Adding Task Log permissions'); $perms->add_object('app', 'Task Logs', 'task_log', 11, 0, 'axo'); $all_mods = $perms->get_group_id('all', null, 'axo'); $nonadmin = $perms->get_group_id('non_admin', null, 'axo'); $perms->add_group_object($all_mods, 'app', 'task_log', 'axo'); $perms->add_group_object($nonadmin, 'app', 'task_log', 'axo'); case '20050316': include DP_BASE_DIR . '/db/upgrade_contacts_company.php'; case '20070521': // DP2.1RC2 // DP2.1RC2 case '20071014': // DP2.1 // Add view of users table to guest and project worker roles $guest = $perms->get_group_id('guest', null, 'aro'); $worker = $perms->get_group_id('normal', null, 'aro'); $perms->add_acl(array('application' => array('view')), null, array($worker, $guest), array('app' => array('users')), null, 1, 1, null, null, 'user'); // TODO: Add new versions here. Keep this message above the default label. // TODO: Add new versions here. Keep this message above the default label. case '20071104': // Last changed date. // Add the permissions for task_log dPmsg('Adding File Folder permissions'); $perms->add_object('app', 'File Folders', 'file_folders', 6, 0, 'axo'); $all_mods = $perms->get_group_id('all', null, 'axo'); $nonadmin = $perms->get_group_id('non_admin', null, 'axo'); $perms->add_group_object($all_mods, 'app', 'file_folders', 'axo'); $perms->add_group_object($nonadmin, 'app', 'file_folders', 'axo'); case '20071114': case '20071204': case '20071218': default: break; } return $latest_update; }