![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: system.class.php 156 2008-04-11 15:47:40Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/system/system.class.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 //fixed system SysVals to prevent their deletion 7 $fixedSysVals = array('CompanyType', 'EventType', 'FileType', 'GlobalCountries', 'GlobalYesNo', 'ProjectPriority', 'ProjectStatus', 'ProjectType', 'TaskDurationType', 'TaskLogReference', 'TaskPriority', 'TaskStatus', 'TaskType', 'UserType'); 8 9 /** 10 * Preferences class 11 */ 12 class CPreferences { 13 var $pref_user = null; 14 var $pref_name = null; 15 var $pref_value = null; 16 17 function CPreferences() { 18 // empty constructor 19 } 20 21 function bind($hash) { 22 if (!is_array($hash)) { 23 return 'CPreferences::bind failed'; 24 } else { 25 $q = new DBQuery; 26 $q->bindHashToObject($hash, $this); 27 $q->clear(); 28 return null; 29 } 30 } 31 32 function check() { 33 // TODO MORE 34 return null; // object is ok 35 } 36 37 function store() { 38 $msg = $this->check(); 39 if ($msg) { 40 return 'CPreference::store-check failed ' . $msg; 41 } 42 if (($msg = $this->delete())) { 43 return 'CPreference::store-delete failed ' . $msg; 44 } 45 $q = new DBQuery; 46 if (!($ret = $q->insertObject('user_preferences', $this))) { 47 $q->clear(); 48 return 'CPreference::store failed ' . db_error(); 49 } else { 50 $q->clear(); 51 return null; 52 } 53 } 54 55 function delete() { 56 $q = new DBQuery; 57 $q->setDelete('user_preferences'); 58 $q->addWhere('pref_user = ' . (int)$this->pref_user); 59 $q->addWhere('pref_name = \'' . $this->pref_name . '\''); 60 if (!$q->exec()) { 61 $q->clear(); 62 return db_error(); 63 } else { 64 $q->clear(); 65 return null; 66 } 67 } 68 } 69 70 /** 71 * Module class 72 */ 73 class CModule extends CW2pObject { 74 var $mod_id = null; 75 var $mod_name = null; 76 var $mod_directory = null; 77 var $mod_version = null; 78 var $mod_setup_class = null; 79 var $mod_type = null; 80 var $mod_active = null; 81 var $mod_ui_name = null; 82 var $mod_ui_icon = null; 83 var $mod_ui_order = null; 84 var $mod_ui_active = null; 85 var $mod_description = null; 86 var $permissions_item_label = null; 87 var $permissions_item_field = null; 88 var $permissions_item_table = null; 89 var $mod_main_class = null; 90 91 function CModule() { 92 $this->CW2pObject('modules', 'mod_id'); 93 } 94 95 function install() { 96 $q = new DBQuery; 97 $q->addTable('modules'); 98 $q->addQuery('mod_directory'); 99 $q->addWhere('mod_directory = \'' . $this->mod_directory . '\''); 100 if ($temp = $q->loadHash()) { 101 // the module is already installed 102 // TODO: check for older version - upgrade 103 return false; 104 } 105 106 $q = new DBQuery; 107 $q->addTable('modules'); 108 $q->addQuery('MAX(mod_ui_order)'); 109 $q->addWhere('mod_name NOT LIKE \'Public\''); 110 // We need to account for "pre-installed" modules that are "UI Inaccessible" 111 // in order to make sure we get the "correct" initial value for . 112 // mod_ui_order values of "UI Inaccessible" modules are irrelevant 113 // and should probably be set to 0 so as not to interfere. 114 115 $this->mod_ui_order = $q->loadResult() + 1; 116 $this->store(); 117 118 $perms = &$GLOBALS['AppUI']->acl(); 119 $perms->addModule($this->mod_directory, $this->mod_name); 120 // Determine if it is an admin module or not, then add it to the correct set 121 if (!isset($this->mod_admin)) { 122 $this->mod_admin = 0; 123 } 124 if ($this->mod_admin) { 125 $perms->addGroupItem($this->mod_directory, "admin"); 126 } else { 127 $perms->addGroupItem($this->mod_directory, "non_admin"); 128 } 129 if (isset($this->permissions_item_table) && $this->permissions_item_table) { 130 $perms->addModuleSection($this->permissions_item_table); 131 } 132 return true; 133 } 134 135 function remove() { 136 $q = new DBQuery; 137 $q->setDelete('modules'); 138 $q->addWhere('mod_id = ' . (int)$this->mod_id); 139 if (!$q->exec()) { 140 $q->clear(); 141 return db_error(); 142 } else { 143 $perms = &$GLOBALS['AppUI']->acl(); 144 if (!isset($this->mod_admin)) 145 $this->mod_admin = 0; 146 if ($this->mod_admin) { 147 $perms->deleteGroupItem($this->mod_directory, 'admin'); 148 } else { 149 $perms->deleteGroupItem($this->mod_directory, 'non_admin'); 150 } 151 $perms->deleteModuleItems($this->mod_directory); 152 $perms->deleteModule($this->mod_directory); 153 if (isset($this->permissions_item_table) && $this->permissions_item_table) { 154 $perms->deleteModuleSection($this->permissions_item_table); 155 } 156 return null; 157 } 158 } 159 160 function move($dirn) { 161 $new_ui_order = $this->mod_ui_order; 162 163 $q = new DBQuery; 164 $q->addTable('modules'); 165 $q->addWhere('mod_id <> ' . (int)$this->mod_id); 166 $q->addOrder('mod_ui_order'); 167 $modules = $q->loadList(); 168 $q->clear(); 169 170 if ($dirn == 'moveup') { 171 $other_new = $new_ui_order; 172 $new_ui_order--; 173 } elseif ($dirn == 'movedn') { 174 $other_new = $new_ui_order; 175 $new_ui_order++; 176 } elseif ($dirn == 'movefirst') { 177 $other_new = $new_ui_order; 178 $new_ui_order = 1; 179 } elseif ($dirn == 'movelast') { 180 $other_new = $new_ui_order; 181 $new_ui_order = count($modules) + 1; 182 } 183 184 if ($new_ui_order && ($new_ui_order <= count($modules) + 1)) { //make sure we aren't going "up" to 0 185 $q = new DBQuery; 186 $q->addTable('modules'); 187 $q->addUpdate('mod_ui_order', $new_ui_order); 188 $q->addWhere('mod_id = ' . (int)$this->mod_id); 189 $q->exec(); 190 $q->clear(); 191 $idx = 1; 192 foreach ($modules as $module) { 193 if ((int)$idx != (int)$new_ui_order) { 194 $q->addTable('modules'); 195 $q->addUpdate('mod_ui_order', $idx); 196 $q->addWhere('mod_id = ' . (int)$module['mod_id']); 197 $q->exec(); 198 $q->clear(); 199 $idx++; 200 } else { 201 $q->addTable('modules'); 202 $q->addUpdate('mod_ui_order', $idx + 1); 203 $q->addWhere('mod_id = ' . (int)$module['mod_id']); 204 $q->exec(); 205 $q->clear(); 206 $idx = $idx + 2; 207 } 208 } 209 } 210 } 211 // overridable functions 212 function moduleInstall() { 213 return null; 214 } 215 function moduleRemove() { 216 return null; 217 } 218 function moduleUpgrade() { 219 return null; 220 } 221 } 222 223 /** 224 * Configuration class 225 */ 226 class CConfig extends CW2pObject { 227 228 function CConfig() { 229 $this->CW2pObject('config', 'config_id'); 230 } 231 232 function getChildren($id) { 233 $this->_query->clear(); 234 $this->_query->addTable('config_list'); 235 $this->_query->addOrder('config_list_id'); 236 $this->_query->addWhere('config_id = ' . (int)$id); 237 $result = $this->_query->loadHashList('config_list_id'); 238 $this->_query->clear(); 239 return $result; 240 } 241 242 } 243 244 class bcode extends CW2pObject { 245 var $_billingcode_id = null; 246 var $company_id; 247 var $billingcode_id = null; 248 var $billingcode_desc; 249 var $billingcode_name; 250 var $billingcode_value; 251 var $billingcode_status; 252 253 function bcode() { 254 $this->CW2pObject('billingcode', 'billingcode_id'); 255 } 256 257 function bind($hash) { 258 if (!is_array($hash)) { 259 return 'Billing Code::bind failed'; 260 } else { 261 $q = new DBQuery; 262 $q->bindHashToObject($hash, $this); 263 $q->clear(); 264 return null; 265 } 266 } 267 268 function delete() { 269 $q = new DBQuery; 270 $q->addTable('billingcode'); 271 $q->addUpdate('billingcode_status', '1'); 272 $q->addWhere('billingcode_id = ' . (int)$this->_billingcode_id); 273 if (!$q->exec()) { 274 $q->clear(); 275 return db_error(); 276 } else { 277 $q->clear(); 278 return null; 279 } 280 } 281 282 function store() { 283 $q = new DBQuery; 284 $q->addQuery('billingcode_id'); 285 $q->addTable('billingcode'); 286 $q->addWhere('billingcode_name = \'' . $this->billingcode_name . '\''); 287 $q->addWhere('company_id = ' . (int)$this->company_id); 288 $found_id = $q->loadResult(); 289 $q->clear(); 290 291 if ($found_id && $found_id != $this->_billingcode_id) { 292 return 'Billing Code::code already exists'; 293 } elseif ($this->_billingcode_id) { 294 $q->addTable('billingcode'); 295 $q->addUpdate('billingcode_desc', $this->billingcode_desc); 296 $q->addUpdate('billingcode_name', $this->billingcode_name); 297 $q->addUpdate('billingcode_value', $this->billingcode_value); 298 $q->addUpdate('billingcode_status', $this->billingcode_status); 299 $q->addUpdate('company_id', $this->company_id); 300 $q->addWhere('billingcode_id = ' . (int)$this->_billingcode_id); 301 $q->exec(); 302 $q->clear(); 303 } elseif (!($ret = $q->insertObject('billingcode', $this, 'billingcode_id'))) { 304 return 'Billing Code::store failed <br />' . db_error(); 305 } else { 306 return null; 307 } 308 } 309 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jan 8 03:00:03 2009 | Cross-referenced by PHPXref 0.7 |