PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/saf/lib/Session/Manager.php

https://github.com/lux/sitellite
PHP | 1691 lines | 881 code | 472 blank | 338 comment | 36 complexity | 3ac27c6be2957a03357115fd3dac1ba2 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, Apache-2.0, GPL-3.0
  1. <?php
  2. loader_import ('saf.File');
  3. /**
  4. * @package Session
  5. */
  6. class SessionManager {
  7. function SessionManager () {
  8. $this->user = new SessionManager_User;
  9. $this->role = new SessionManager_Role;
  10. $this->team = new SessionManager_Team;
  11. $this->resource = new SessionManager_Resource;
  12. $this->access = new SessionManager_Access;
  13. $this->status = new SessionManager_Status;
  14. $this->pref = new SessionManager_Pref;
  15. }
  16. }
  17. /**
  18. * @package Session
  19. */
  20. class SessionManager_User {
  21. /* Format: Dependent on Session Source driver */
  22. /**
  23. * Number of users.
  24. */
  25. var $total;
  26. /**
  27. * Error message, if an error occurs.
  28. */
  29. var $error;
  30. /**
  31. * Returns a list of users.
  32. *
  33. * @return array
  34. */
  35. function getList ($offset = false, $limit = false, $order, $ascdesc, $role = false, $team = false, $name = false, $disabled = false, $public = false, $teams = false) {
  36. $res = session_user_get_list ($offset, $limit, $order, $ascdesc, $role, $team, $name, $disabled, $public, $teams);
  37. if (! $res) {
  38. $this->error = session_user_error ();
  39. return false;
  40. }
  41. $this->total = session_user_total ();
  42. return $res;
  43. }
  44. /**
  45. * Adds a user to the system.
  46. *
  47. * @param array hash
  48. * @return boolean
  49. */
  50. function add ($data) {
  51. $res = session_user_add ($data);
  52. if (! $res) {
  53. $this->error = session_user_error ();
  54. }
  55. return $res;
  56. }
  57. /**
  58. * Modifies a user in the system.
  59. *
  60. * @param string
  61. * @param array hash
  62. * @return boolean
  63. */
  64. function edit ($user, $data) {
  65. $res = session_user_edit ($user, $data);
  66. if (! $res) {
  67. $this->error = session_user_error ();
  68. }
  69. return $res;
  70. }
  71. /**
  72. * Deletes a user from the system.
  73. *
  74. * @param string
  75. * @return boolean
  76. */
  77. function delete ($user) {
  78. $res = session_user_delete ($user);
  79. if (! $res) {
  80. $this->error = session_user_error ();
  81. }
  82. return $res;
  83. }
  84. /**
  85. * Generate a form for adding items to this list.
  86. *
  87. * @return object saf.MailForm object
  88. */
  89. function &getAddForm () {
  90. loader_import ('saf.MailForm');
  91. $form = new MailForm;
  92. $form->action = site_prefix () . '/index/usradm-add-user-action';
  93. $form->error_mode = 'all';
  94. loader_import ('ext.phpsniff');
  95. $sniffer = new phpSniff;
  96. $form->_browser = $sniffer->property ('browser');
  97. $form->addWidget ('hidden', '_list');
  98. page_add_script ('
  99. formhelp_prepend = \'<table border="0" cellpadding="0"><tr><td width="12" valign="top"><img src="' . site_prefix () . '/inc/app/cms/pix/arrow-10px.gif" alt="" border="0" /></td><td valign="top">\';
  100. formhelp_append = \'</td></tr></table>\';
  101. ');
  102. $w =& $form->addWidget ('tab', 'tab1');
  103. $w->title = intl_get ('Account');
  104. //$w =& $form->addWidget ('section', 'section1');
  105. //$w->title = intl_get ('Basic Information (Required)');
  106. $w =& $form->addWidget ('text', '_username');
  107. $w->alt = intl_get ('Username');
  108. $w->addRule ('not empty', intl_get ('Username must not be empty.'));
  109. $w->addRule ('unique "sitellite_user/username"', intl_get ('Username already in use.'));
  110. $w->extra = 'maxlength="48"';
  111. $w =& $form->addWidget ('password', 'passwd');
  112. $w->alt = intl_get ('Password');
  113. $w->addRule ('not empty', intl_get ('Password must not be empty.'));
  114. $w->ignoreEmpty = false;
  115. $w =& $form->addWidget ('password', 'password_verify');
  116. $w->alt = intl_get ('Verify Password');
  117. $w->addRule ('equals "passwd"', intl_get ('Passwords do not match.'));
  118. $w->ignoreEmpty = false;
  119. $w =& $form->addWidget ('text', 'firstname');
  120. $w->alt = intl_get ('First Name');
  121. //$w->addRule ('not empty', intl_get ('First name must not be empty.'));
  122. $w->extra = 'maxlength="32"';
  123. $w =& $form->addWidget ('text', 'lastname');
  124. $w->alt = intl_get ('Last Name');
  125. //$w->addRule ('not empty', intl_get ('Last name must not be empty.'));
  126. $w->extra = 'maxlength="32"';
  127. $w =& $form->addWidget ('text', 'email');
  128. $w->alt = intl_get ('Email');
  129. //$w->addRule ('not empty', intl_get ('Email must not be empty.'));
  130. //$w->addRule ('contains "@"', intl_get ('Email does not appear to be valid.'));
  131. $w->extra = 'maxlength="42"';
  132. $snm =& session_get_manager ();
  133. $list = assocify (array_keys ($snm->role->getList ()));
  134. unset ($list['anonymous']);
  135. unset ($list['']);
  136. $w =& $form->addWidget ('select', 'role');
  137. $w->alt = intl_get ('Role');
  138. $w->setValues ($list);
  139. $w->extra = 'id="role"';
  140. $w =& $form->addWidget ('select', 'team');
  141. $w->alt = intl_get ('Team');
  142. $w->setValues (assocify (array_keys ($snm->team->getList ())));
  143. $w->extra = 'id="team"';
  144. $w =& $form->addWidget ('select', 'disabled');
  145. $w->alt = intl_get ('Disabled');
  146. $w->setValues (array ('yes' => 'Yes', 'no' => 'No'));
  147. $w->setValue ('no');
  148. $w->extra = 'id="disabled"';
  149. $w =& $form->addWidget ('select', 'public');
  150. $w->alt = intl_get ('Public');
  151. $w->setValues (array ('yes' => 'Yes', 'no' => 'No'));
  152. $w->setValue ('no');
  153. $w->extra = 'id="public"';
  154. $w =& $form->addWidget ('textarea', 'profile');
  155. $w->alt = intl_get ('Profile');
  156. $w->labelPosition = 'left';
  157. $w->rows = 5;
  158. $w->extra = 'id="profile"';
  159. $w =& $form->addWidget ('textarea', 'sig');
  160. $w->alt = intl_get ('Signature (for comments)');
  161. $w->labelPosition = 'left';
  162. $w->rows = 3;
  163. $w->extra = 'id="sig"';
  164. $w =& $form->addWidget ('tab', 'tab2');
  165. $w->title = intl_get ('Contact');
  166. //$w =& $form->addWidget ('section', 'section2');
  167. //$w->title = intl_get ('Extended Information (Optional)');
  168. $w =& $form->addWidget ('text', 'company');
  169. $w->alt = intl_get ('Company');
  170. $w->extra = 'maxlength="48"';
  171. $w =& $form->addWidget ('text', 'position');
  172. $w->alt = intl_get ('Position');
  173. $w->extra = 'maxlength="48"';
  174. $w =& $form->addWidget ('text', 'website');
  175. $w->alt = intl_get ('Web Site');
  176. $w->setValue ('http://');
  177. $w->extra = 'maxlength="72"';
  178. $w =& $form->addWidget ('text', 'phone');
  179. $w->alt = intl_get ('Phone #');
  180. $w->extra = 'maxlength="24"';
  181. $w =& $form->addWidget ('text', 'cell');
  182. $w->alt = intl_get ('Cell #');
  183. $w->extra = 'maxlength="24"';
  184. $w =& $form->addWidget ('text', 'fax');
  185. $w->alt = intl_get ('Fax #');
  186. $w->extra = 'maxlength="24"';
  187. $w =& $form->addWidget ('text', 'sms_address');
  188. $w->alt = intl_get ('SMS #');
  189. $w->extra = 'maxlength="72"';
  190. $w =& $form->addWidget ('text', 'jabber_id');
  191. $w->alt = intl_get ('Jabber ID');
  192. $w->extra = 'maxlength="48"';
  193. $w =& $form->addWidget ('text', 'address1');
  194. $w->alt = intl_get ('Address');
  195. $w->extra = 'maxlength="72"';
  196. $w =& $form->addWidget ('text', 'address2');
  197. $w->alt = intl_get ('Address Line 2');
  198. $w->extra = 'maxlength="72"';
  199. $w =& $form->addWidget ('text', 'city');
  200. $w->alt = intl_get ('City');
  201. $w->extra = 'maxlength="48"';
  202. $w =& $form->addWidget ('text', 'province');
  203. $w->alt = intl_get ('Province/State');
  204. $w->extra = 'maxlength="48"';
  205. $w =& $form->addWidget ('text', 'postal_code');
  206. $w->alt = intl_get ('Postal/Zip Code');
  207. $w->extra = 'maxlength="16"';
  208. $w =& $form->addWidget ('text', 'country');
  209. $w->alt = intl_get ('Country');
  210. $w->extra = 'maxlength="48"';
  211. $w =& $form->addWidget ('tab', 'tab3');
  212. $w->title = intl_get ('Access');
  213. $w =& $form->addWidget ('usradm.Widget.Allowedbox', 'teams');
  214. $w->alt = 'Allowed Teams';
  215. $w->headers[] = '&nbsp;';
  216. $w->headers[] = intl_get ('Read');
  217. $w->headers[] = intl_get ('Write');
  218. $b =& $w->addButton ('all', array ('r' => '', 'w' => ''));
  219. $b->alt = '<strong>All</strong>';
  220. $b->setValue (array ('r', 'w'));
  221. $b->extra = 'class="teams" onclick="teams_select_all (this)"';
  222. foreach (session_get_teams () as $value) {
  223. $b =& $w->addButton ($value, array ('r' => '', 'w' => ''));
  224. $b->alt = ucwords (str_replace ('_', ' ', $value));
  225. $b->extra = 'class="teams"';
  226. }
  227. $w =& $form->addWidget ('tab', 'tab-end');
  228. $w =& $form->addWidget ('msubmit', 'submit_button');
  229. $b =& $w->getButton ();
  230. $b->setValues (intl_get ('Save'));
  231. $b =& $w->addButton ('cancel_button');
  232. $b->setValues (intl_get ('Cancel'));
  233. $b->extra = 'onclick="window.location.href = \'' . site_prefix () . '/index/usradm-browse-action?list=users\'; return false"';
  234. return $form;
  235. }
  236. /**
  237. * Generate a form for editing items in this list.
  238. *
  239. * @return object saf.MailForm object
  240. */
  241. function &getEditForm ($item) {
  242. loader_import ('saf.MailForm');
  243. $form = new MailForm;
  244. $form->action = site_prefix () . '/index/usradm-edit-user-action';
  245. $form->error_mode = 'all';
  246. loader_import ('ext.phpsniff');
  247. $sniffer = new phpSniff;
  248. $form->_browser = $sniffer->property ('browser');
  249. $user = session_user_get ($item);
  250. $form->addWidget ('hidden', '_list');
  251. page_add_script ('
  252. formhelp_prepend = \'<table border="0" cellpadding="0"><tr><td width="12" valign="top"><img src="' . site_prefix () . '/inc/app/cms/pix/arrow-10px.gif" alt="" border="0" /></td><td valign="top">\';
  253. formhelp_append = \'</td></tr></table>\';
  254. ');
  255. $w =& $form->addWidget ('tab', 'tab1');
  256. $w->title = intl_get ('Account');
  257. $w =& $form->addWidget ('info', '_key');
  258. $w->alt = intl_get ('Username');
  259. $w->extra = 'maxlength="48"';
  260. $w =& $form->addWidget ('password', 'passwd');
  261. $w->alt = intl_get ('Password');
  262. $w =& $form->addWidget ('password', 'password_verify');
  263. $w->alt = intl_get ('Verify Password');
  264. $w->addRule ('equals "passwd"', intl_get ('Passwords do not match.'));
  265. $w->ignoreEmpty = false;
  266. $w =& $form->addWidget ('text', 'firstname');
  267. $w->alt = intl_get ('First Name');
  268. //$w->addRule ('not empty', intl_get ('First name must not be empty.'));
  269. $w->setValue ($user->firstname);
  270. $w->extra = 'maxlength="32"';
  271. $w =& $form->addWidget ('text', 'lastname');
  272. $w->alt = intl_get ('Last Name');
  273. //$w->addRule ('not empty', intl_get ('Last name must not be empty.'));
  274. $w->setValue ($user->lastname);
  275. $w->extra = 'maxlength="32"';
  276. $w =& $form->addWidget ('text', 'email');
  277. $w->alt = intl_get ('Email');
  278. //$w->addRule ('not empty', intl_get ('Email must not be empty.'));
  279. //$w->addRule ('contains "@"', intl_get ('Email does not appear to be valid.'));
  280. $w->setValue ($user->email);
  281. $w->extra = 'maxlength="42"';
  282. $snm =& session_get_manager ();
  283. $list = assocify (array_keys ($snm->role->getList ()));
  284. unset ($list['anonymous']);
  285. unset ($list['']);
  286. $w =& $form->addWidget ('select', 'role');
  287. $w->alt = intl_get ('Role');
  288. $w->setValues ($list);
  289. $w->setValue ($user->role);
  290. $w->extra = 'id="role"';
  291. $w =& $form->addWidget ('select', 'team');
  292. $w->alt = intl_get ('Team');
  293. $w->setValues (assocify (array_keys ($snm->team->getList ())));
  294. $w->setValue ($user->team);
  295. $w->extra = 'id="team"';
  296. $w =& $form->addWidget ('select', 'disabled');
  297. $w->alt = intl_get ('Disabled');
  298. $w->setValues (array ('yes' => 'Yes', 'no' => 'No'));
  299. $w->setValue ($user->disabled);
  300. $w->extra = 'id="disabled"';
  301. $w =& $form->addWidget ('select', 'public');
  302. $w->alt = intl_get ('Public');
  303. $w->setValues (array ('yes' => 'Yes', 'no' => 'No'));
  304. $w->setValue ($user->public);
  305. $w->extra = 'id="public"';
  306. $w =& $form->addWidget ('textarea', 'profile');
  307. $w->alt = intl_get ('Profile');
  308. $w->setValue ($user->profile);
  309. $w->labelPosition = 'left';
  310. $w->rows = 5;
  311. $w->extra = 'id="profile"';
  312. $w =& $form->addWidget ('textarea', 'sig');
  313. $w->alt = intl_get ('Signature (for comments)');
  314. $w->setValue ($user->sig);
  315. $w->labelPosition = 'left';
  316. $w->rows = 3;
  317. $w->extra = 'id="sig"';
  318. $w =& $form->addWidget ('info', 'registered');
  319. $w->alt = intl_get ('Date Registered');
  320. $w->setValue (loader_call ('saf.Date', 'Date::timestamp', $user->registered, 'F jS, Y - g:i A'));
  321. $w =& $form->addWidget ('info', 'modified');
  322. $w->alt = intl_get ('Date Last Modified');
  323. $w->setValue (loader_call ('saf.Date', 'Date::timestamp', $user->modified, 'F jS, Y - g:i A'));
  324. $w =& $form->addWidget ('tab', 'tab2');
  325. $w->title = intl_get ('Contact');
  326. $w =& $form->addWidget ('text', 'company');
  327. $w->alt = intl_get ('Company');
  328. $w->setValue ($user->company);
  329. $w->extra = 'maxlength="48"';
  330. $w =& $form->addWidget ('text', 'position');
  331. $w->alt = intl_get ('Position');
  332. $w->setValue ($user->position);
  333. $w->extra = 'maxlength="48"';
  334. $w =& $form->addWidget ('text', 'website');
  335. $w->alt = intl_get ('Web Site');
  336. if (! empty ($user->website)) {
  337. $w->setValue ($user->website);
  338. } else {
  339. $w->setValue ('http://');
  340. }
  341. $w->extra = 'maxlength="72"';
  342. $w =& $form->addWidget ('text', 'phone');
  343. $w->alt = intl_get ('Phone #');
  344. $w->setValue ($user->phone);
  345. $w->extra = 'maxlength="24"';
  346. $w =& $form->addWidget ('text', 'cell');
  347. $w->alt = intl_get ('Cell #');
  348. $w->setValue ($user->cell);
  349. $w->extra = 'maxlength="24"';
  350. $w =& $form->addWidget ('text', 'fax');
  351. $w->alt = intl_get ('Fax #');
  352. $w->setValue ($user->fax);
  353. $w->extra = 'maxlength="24"';
  354. $w =& $form->addWidget ('text', 'sms_address');
  355. $w->alt = intl_get ('SMS #');
  356. $w->setValue ($user->sms_address);
  357. $w->extra = 'maxlength="72"';
  358. $w =& $form->addWidget ('text', 'jabber_id');
  359. $w->alt = intl_get ('Jabber ID');
  360. $w->setValue ($user->jabber_id);
  361. $w->extra = 'maxlength="48"';
  362. $w =& $form->addWidget ('text', 'address1');
  363. $w->alt = intl_get ('Address');
  364. $w->setValue ($user->address1);
  365. $w->extra = 'maxlength="72"';
  366. $w =& $form->addWidget ('text', 'address2');
  367. $w->alt = intl_get ('Address Line 2');
  368. $w->setValue ($user->address2);
  369. $w->extra = 'maxlength="72"';
  370. $w =& $form->addWidget ('text', 'city');
  371. $w->alt = intl_get ('City');
  372. $w->setValue ($user->city);
  373. $w->extra = 'maxlength="48"';
  374. $w =& $form->addWidget ('text', 'province');
  375. $w->alt = intl_get ('Province/State');
  376. $w->setValue ($user->province);
  377. $w->extra = 'maxlength="48"';
  378. $w =& $form->addWidget ('text', 'postal_code');
  379. $w->alt = intl_get ('Postal/Zip Code');
  380. $w->setValue ($user->postal_code);
  381. $w->extra = 'maxlength="16"';
  382. $w =& $form->addWidget ('text', 'country');
  383. $w->alt = intl_get ('Country');
  384. $w->setValue ($user->country);
  385. $w->extra = 'maxlength="48"';
  386. $w =& $form->addWidget ('tab', 'tab3');
  387. $w->title = intl_get ('Access');
  388. $w =& $form->addWidget ('usradm.Widget.Allowedbox', 'teams');
  389. $w->alt = 'Allowed Teams';
  390. $w->headers[] = '&nbsp;';
  391. $w->headers[] = intl_get ('Read');
  392. $w->headers[] = intl_get ('Write');
  393. $b =& $w->addButton ('all', array ('r' => '', 'w' => ''));
  394. $b->alt = '<strong>All</strong>';
  395. $b->extra = 'class="teams" onclick="teams_select_all (this)"';
  396. $teams = unserialize ($user->teams);
  397. if (isset ($teams['all'])) {
  398. $b->setValue (assocify (preg_split ('//', $teams['all'], -1, PREG_SPLIT_NO_EMPTY)));
  399. }
  400. foreach (session_get_teams () as $value) {
  401. $b =& $w->addButton ($value, array ('r' => '', 'w' => ''));
  402. $b->alt = ucwords (str_replace ('_', ' ', $value));
  403. $b->setValue (assocify (preg_split ('//', $teams[$value], -1, PREG_SPLIT_NO_EMPTY)));
  404. $b->extra = 'class="teams"';
  405. }
  406. $w =& $form->addWidget ('tab', 'tab-end');
  407. $w =& $form->addWidget ('msubmit', 'submit_button');
  408. $b =& $w->getButton ();
  409. $b->setValues (intl_get ('Save'));
  410. $b =& $w->addButton ('cancel_button');
  411. $b->setValues (intl_get ('Cancel'));
  412. $b->extra = 'onclick="window.location.href = \'' . site_prefix () . '/index/usradm-browse-action?list=users\'; return false"';
  413. return $form;
  414. }
  415. }
  416. /**
  417. * @package Session
  418. */
  419. class SessionManager_Role { // Lives in inc/conf/auth/roles/${name}.php
  420. /* INI Format:
  421. * [role]
  422. * name = master
  423. * admin = yes
  424. * disabled = no
  425. * [allow:resources]
  426. * all = rw
  427. * [allow:access]
  428. * all = rw
  429. * [allow:status]
  430. * all = rw
  431. */
  432. /**
  433. * Directory to store info.
  434. */
  435. var $dir = 'inc/conf/auth/roles';
  436. /**
  437. * Parsed data from file.
  438. */
  439. var $data = array ();
  440. /**
  441. * Error message, if an error occurs.
  442. */
  443. var $error;
  444. /**
  445. * Constructor method.
  446. */
  447. function SessionManager_Role () {
  448. loader_import ('saf.File.Directory');
  449. $this->getData ();
  450. }
  451. /**
  452. * Retrieves the data from and stores it in $data.
  453. */
  454. function getData () {
  455. foreach (Dir::find ('*.php', $this->dir, false) as $file) {
  456. if (strpos ($file, '.') === 0) {
  457. continue;
  458. }
  459. $inidata = ini_parse ($file, true);
  460. $this->data[$inidata['role']['name']] = $inidata;
  461. }
  462. }
  463. /**
  464. * Returns an array of the data.
  465. *
  466. * @return array
  467. */
  468. function getList () {
  469. return $this->data;
  470. }
  471. /**
  472. * Adds an item to $data and rewrites the INI file.
  473. *
  474. * @param string
  475. * @param boolean
  476. * @return boolean
  477. */
  478. function add ($name, $data) {
  479. if (strstr ($name, '..')) {
  480. $this->error = 'Invalid role name!';
  481. return false;
  482. }
  483. $this->data[$name] = $data;
  484. $r = file_overwrite ($this->dir . '/' . $name . '.php', ini_write ($this->data[$name]));
  485. if (! $r) {
  486. $this->error = 'Failed to write INI file!';
  487. }
  488. return $r;
  489. }
  490. /**
  491. * Renames an item in $data and rewrites the INI file.
  492. *
  493. * @param string
  494. * @param string
  495. * @param array hash
  496. * @return boolean
  497. */
  498. function edit ($name, $newname, $data) {
  499. if (strstr ($name, '..')) {
  500. $this->error = 'Invalid role name!';
  501. return false;
  502. }
  503. if (strstr ($newname, '..')) {
  504. $this->error = 'Invalid role name!';
  505. return false;
  506. }
  507. unset ($this->data[$name]);
  508. $r = unlink ($this->dir . '/' . $name . '.php');
  509. if (! $r) {
  510. $this->error = 'Failed to remove INI file!';
  511. }
  512. $this->data[$newname] = $data;
  513. $r = file_overwrite ($this->dir . '/' . $newname . '.php', ini_write ($this->data[$newname]));
  514. if (! $r) {
  515. $this->error = 'Failed to write INI file!';
  516. }
  517. return $r;
  518. }
  519. /**
  520. * Deletes an item from $data and rewrites the INI file.
  521. *
  522. * @param string
  523. * @return boolean
  524. */
  525. function delete ($name) {
  526. if (strstr ($name, '..')) {
  527. $this->error = 'Invalid role name!';
  528. return false;
  529. }
  530. unset ($this->data[$name]);
  531. $r = unlink ($this->dir . '/' . $name . '.php');
  532. if (! $r) {
  533. $this->error = 'Failed to remove INI file!';
  534. }
  535. return $r;
  536. }
  537. /**
  538. * Generate a form for adding items to this list.
  539. *
  540. * @return object saf.MailForm object
  541. */
  542. function &getAddForm () {
  543. loader_import ('saf.MailForm');
  544. $form = new MailForm;
  545. $form->action = site_prefix () . '/index/usradm-add-role-action';
  546. $form->error_mode = 'all';
  547. $form->addWidget ('hidden', '_list');
  548. $w =& $form->addWidget ('tab', 'tab1');
  549. $w->title = intl_get ('Edit');
  550. $w =& $form->addWidget ('text', 'name');
  551. $w->alt = intl_get ('Name');
  552. $w->addRule ('not empty', intl_get ('Role name must not be empty.'));
  553. $w->addRule ('regex "^[-a-zA-Z0-9_]+$"', intl_get ('Role same should only contains alphanumeric characters or underscores.'));
  554. $w->extra = 'maxlength="48"';
  555. $w =& $form->addWidget ('select', 'admin');
  556. $w->alt = intl_get ('Is admin?');
  557. $w->setValues (array ('yes' => 'Yes', 'no' => 'No'));
  558. $w->setValue ('no');
  559. $w->extra = 'id="admin"';
  560. $w =& $form->addWidget ('select', 'disabled');
  561. $w->alt = intl_get ('Disabled');
  562. $w->setValues (array ('yes' => 'Yes', 'no' => 'No'));
  563. $w->setValue ('no');
  564. $w->extra = 'id="disabled"';
  565. $w =& $form->addWidget ('tab', 'tab2');
  566. $w->title = intl_get ('Resources');
  567. $w =& $form->addWidget ('usradm.Widget.Allowedbox', 'resources');
  568. $w->alt = 'Allowed Resources';
  569. $w->headers[] = '&nbsp;';
  570. $w->headers[] = intl_get ('Read');
  571. $w->headers[] = intl_get ('Write');
  572. $b =& $w->addButton ('all', array ('r' => '', 'w' => ''));
  573. $b->alt = '<strong>All</strong>';
  574. $b->extra = 'class="resources" onclick="resources_select_all (this)"';
  575. loader_import ('usradm.Functions');
  576. $resources = array ();
  577. foreach (session_get_resources () as $value) {
  578. $resources[$value] = usradm_resource_name ($value);
  579. }
  580. asort ($resources);
  581. foreach ($resources as $key => $value) {
  582. $b =& $w->addButton ($key, array ('r' => '', 'w' => ''));
  583. $b->alt = $value;
  584. $b->extra = 'class="resources"';
  585. }
  586. $w =& $form->addWidget ('tab', 'tab3');
  587. $w->title = intl_get ('Access Levels');
  588. $w =& $form->addWidget ('usradm.Widget.Allowedbox', 'accesslevels');
  589. $w->alt = 'Allowed Access Levels';
  590. $w->headers[] = '&nbsp;';
  591. $w->headers[] = intl_get ('Read');
  592. $w->headers[] = intl_get ('Write');
  593. $b =& $w->addButton ('all', array ('r' => '', 'w' => ''));
  594. $b->alt = '<strong>All</strong>';
  595. $b->extra = 'class="access" onclick="access_select_all (this)"';
  596. foreach (session_get_access_levels () as $value) {
  597. $b =& $w->addButton ($value, array ('r' => '', 'w' => ''));
  598. $b->alt = ucwords (str_replace ('_', ' ', $value));
  599. $b->extra = 'class="access"';
  600. }
  601. $w =& $form->addWidget ('tab', 'tab4');
  602. $w->title = intl_get ('Statuses');
  603. $w =& $form->addWidget ('usradm.Widget.Allowedbox', 'statuses');
  604. $w->alt = 'Allowed Statuses';
  605. $w->headers[] = '&nbsp;';
  606. $w->headers[] = intl_get ('Read');
  607. $w->headers[] = intl_get ('Write');
  608. $b =& $w->addButton ('all', array ('r' => '', 'w' => ''));
  609. $b->alt = '<strong>All</strong>';
  610. $b->extra = 'class="status" onclick="status_select_all (this)"';
  611. foreach (session_get_statuses () as $value) {
  612. $b =& $w->addButton ($value, array ('r' => '', 'w' => ''));
  613. $b->alt = ucwords (str_replace ('_', ' ', $value));
  614. $b->extra = 'class="status"';
  615. }
  616. $w =& $form->addWidget ('tab', 'tab-end');
  617. $w =& $form->addWidget ('msubmit', 'submit_button');
  618. $b =& $w->getButton ();
  619. $b->setValues (intl_get ('Save'));
  620. $b =& $w->addButton ('cancel_button');
  621. $b->setValues (intl_get ('Cancel'));
  622. $b->extra = 'onclick="window.location.href = \'' . site_prefix () . '/index/usradm-browse-action?list=roles\'; return false"';
  623. return $form;
  624. }
  625. /**
  626. * Generate a form for editing items in this list.
  627. *
  628. * @return object saf.MailForm object
  629. */
  630. function &getEditForm ($item) {
  631. loader_import ('saf.MailForm');
  632. $form = new MailForm;
  633. $form->action = site_prefix () . '/index/usradm-edit-role-action';
  634. $form->error_mode = 'all';
  635. $form->addWidget ('hidden', '_list');
  636. $form->addWidget ('hidden', '_key');
  637. $w =& $form->addWidget ('tab', 'tab1');
  638. $w->title = intl_get ('Edit');
  639. $w =& $form->addWidget ('text', 'name');
  640. $w->alt = intl_get ('Name');
  641. $w->addRule ('not empty', intl_get ('Role name must not be empty.'));
  642. $w->addRule ('regex "^[-a-zA-Z0-9_]+$"', intl_get ('Role same should only contains alphanumeric characters or underscores.'));
  643. $w->setValue ($item);
  644. $w->extra = 'maxlength="48"';
  645. $w =& $form->addWidget ('select', 'admin');
  646. $w->alt = intl_get ('Is admin?');
  647. $w->setValues (array ('yes' => 'Yes', 'no' => 'No'));
  648. if ($this->data[$item]['role']['admin']) {
  649. $w->setValue ('yes');
  650. } else {
  651. $w->setValue ('no');
  652. }
  653. $w->extra = 'id="admin"';
  654. $w =& $form->addWidget ('select', 'disabled');
  655. $w->alt = intl_get ('Disabled');
  656. $w->setValues (array ('yes' => 'Yes', 'no' => 'No'));
  657. $w->setValue ('no');
  658. if ($this->data[$item]['role']['disabled']) {
  659. $w->setValue ('yes');
  660. } else {
  661. $w->setValue ('no');
  662. }
  663. $w->extra = 'id="disabled"';
  664. $w =& $form->addWidget ('tab', 'tab2');
  665. $w->title = intl_get ('Resources');
  666. $w =& $form->addWidget ('usradm.Widget.Allowedbox', 'resources');
  667. $w->alt = 'Allowed Resources';
  668. $w->headers[] = '&nbsp;';
  669. $w->headers[] = intl_get ('Read');
  670. $w->headers[] = intl_get ('Write');
  671. $b =& $w->addButton ('all', array ('r' => '', 'w' => ''));
  672. $b->alt = '<strong>All</strong>';
  673. $b->setValue (assocify (preg_split ('//', $this->data[$item]['allow:resources']['all'], -1, PREG_SPLIT_NO_EMPTY)));
  674. $b->extra = 'class="resources" onclick="resources_select_all (this)"';
  675. loader_import ('usradm.Functions');
  676. $resources = array ();
  677. foreach (session_get_resources () as $value) {
  678. $resources[$value] = usradm_resource_name ($value);
  679. }
  680. asort ($resources);
  681. foreach ($resources as $key => $value) {
  682. $b =& $w->addButton ($key, array ('r' => '', 'w' => ''));
  683. $b->alt = $value;
  684. $b->setValue (assocify (preg_split ('//', $this->data[$item]['allow:resources'][$key], -1, PREG_SPLIT_NO_EMPTY)));
  685. $b->extra = 'class="resources"';
  686. }
  687. //foreach (session_get_resources () as $value) {
  688. // $b =& $w->addButton ($value, array ('r' => '', 'w' => ''));
  689. // $b->alt = ucwords (str_replace ('_', ' ', $value));
  690. // $b->setValue (assocify (preg_split ('//', $this->data[$item]['allow:resources'][$value], -1, PREG_SPLIT_NO_EMPTY)));
  691. //}
  692. $w =& $form->addWidget ('tab', 'tab3');
  693. $w->title = intl_get ('Access Levels');
  694. $w =& $form->addWidget ('usradm.Widget.Allowedbox', 'accesslevels');
  695. $w->alt = 'Allowed Access Levels';
  696. $w->headers[] = '&nbsp;';
  697. $w->headers[] = intl_get ('Read');
  698. $w->headers[] = intl_get ('Write');
  699. $b =& $w->addButton ('all', array ('r' => '', 'w' => ''));
  700. $b->alt = '<strong>All</strong>';
  701. $b->setValue (assocify (preg_split ('//', $this->data[$item]['allow:access']['all'], -1, PREG_SPLIT_NO_EMPTY)));
  702. $b->extra = 'class="access" onclick="access_select_all (this)"';
  703. foreach (session_get_access_levels () as $value) {
  704. $b =& $w->addButton ($value, array ('r' => '', 'w' => ''));
  705. $b->alt = ucwords (str_replace ('_', ' ', $value));
  706. $b->setValue (assocify (preg_split ('//', $this->data[$item]['allow:access'][$value], -1, PREG_SPLIT_NO_EMPTY)));
  707. $b->extra = 'class="access"';
  708. }
  709. $w =& $form->addWidget ('tab', 'tab4');
  710. $w->title = intl_get ('Statuses');
  711. $w =& $form->addWidget ('usradm.Widget.Allowedbox', 'statuses');
  712. $w->alt = 'Allowed Statuses';
  713. $w->headers[] = '&nbsp;';
  714. $w->headers[] = intl_get ('Read');
  715. $w->headers[] = intl_get ('Write');
  716. $b =& $w->addButton ('all', array ('r' => '', 'w' => ''));
  717. $b->alt = '<strong>All</strong>';
  718. $b->setValue (assocify (preg_split ('//', $this->data[$item]['allow:status']['all'], -1, PREG_SPLIT_NO_EMPTY)));
  719. $b->extra = 'class="status" onclick="status_select_all (this)"';
  720. foreach (session_get_statuses () as $value) {
  721. $b =& $w->addButton ($value, array ('r' => '', 'w' => ''));
  722. $b->alt = ucwords (str_replace ('_', ' ', $value));
  723. $b->setValue (assocify (preg_split ('//', $this->data[$item]['allow:status'][$value], -1, PREG_SPLIT_NO_EMPTY)));
  724. $b->extra = 'class="status"';
  725. }
  726. $w =& $form->addWidget ('tab', 'tab-end');
  727. $w =& $form->addWidget ('msubmit', 'submit_button');
  728. $b =& $w->getButton ();
  729. $b->setValues (intl_get ('Save'));
  730. $b =& $w->addButton ('cancel_button');
  731. $b->setValues (intl_get ('Cancel'));
  732. $b->extra = 'onclick="window.location.href = \'' . site_prefix () . '/index/usradm-browse-action?list=roles\'; return false"';
  733. return $form;
  734. }
  735. }
  736. /**
  737. * @package Session
  738. */
  739. class SessionManager_Pref { // Lives in inc/conf/auth/prefs/index.php
  740. /* INI Format:
  741. * [pref_name]
  742. * alt = Display Name
  743. * instructions = Instructions for site admins
  744. * type = mailform type
  745. * value 1 = first value
  746. * value 2 = second value
  747. * default_value = first value
  748. */
  749. /**
  750. * File to store info.
  751. */
  752. var $file = 'inc/conf/auth/preferences/index.php';
  753. /**
  754. * Parsed data from file.
  755. */
  756. var $data = array ();
  757. /**
  758. * Error message, if an error occurs.
  759. */
  760. var $error;
  761. /**
  762. * Constructor method.
  763. */
  764. function SessionManager_Pref () {
  765. $this->getData ();
  766. }
  767. /**
  768. * Retrieves the data from $file and stores it in $data.
  769. */
  770. function getData () {
  771. $this->data = ini_parse ($this->file, true);
  772. }
  773. /**
  774. * Returns an array of the data.
  775. *
  776. * @return array
  777. */
  778. function getList () {
  779. return $this->data;
  780. }
  781. /**
  782. * Adds an item to $data and rewrites the INI file.
  783. *
  784. * @param string
  785. * @param boolean
  786. * @return boolean
  787. */
  788. function add ($name, $data) {
  789. $this->data[$name] = $data;
  790. $r = file_overwrite ($this->file, ini_write ($this->data));
  791. if (! $r) {
  792. $this->error = 'Failed to write INI file!';
  793. }
  794. return $r;
  795. }
  796. /**
  797. * Renames an item in $data and rewrites the INI file.
  798. *
  799. * @param string
  800. * @param string
  801. * @param array hash
  802. * @return boolean
  803. */
  804. function edit ($name, $newname, $data) {
  805. unset ($this->data[$name]);
  806. $this->data[$newname] = $data;
  807. $r = file_overwrite ($this->file, ini_write ($this->data));
  808. if (! $r) {
  809. $this->error = 'Failed to write INI file!';
  810. }
  811. return $r;
  812. }
  813. /**
  814. * Deletes an item from $data and rewrites the INI file.
  815. *
  816. * @param string
  817. * @return boolean
  818. */
  819. function delete ($name) {
  820. unset ($this->data[$name]);
  821. $r = file_overwrite ($this->file, ini_write ($this->data));
  822. if (! $r) {
  823. $this->error = 'Failed to write INI file!';
  824. }
  825. return $r;
  826. }
  827. /*
  828. * Show as form fields:
  829. * pref_name => text
  830. * alt => text
  831. * type => always 'select' (don't show)
  832. * value n => textarea (one-per-line)
  833. * values => text (in lieu of "value n" enter a function name that returns a value array)
  834. * default_value => text
  835. */
  836. /**
  837. * Generate a form for adding items to this list.
  838. *
  839. * @return object saf.MailForm object
  840. */
  841. function &getAddForm () {
  842. loader_import ('saf.MailForm');
  843. $form = new MailForm;
  844. $form->action = site_prefix () . '/index/usradm-add-pref-action';
  845. $form->error_mode = 'all';
  846. $form->addWidget ('hidden', '_list');
  847. $w =& $form->addWidget ('text', 'pref_name');
  848. $w->alt = intl_get ('Preference Name');
  849. $w->addRule ('not empty', intl_get ('Preference name may not be empty.'));
  850. $w->extra = 'maxlength="32"';
  851. $w =& $form->addWidget ('text', 'alt');
  852. $w->alt = intl_get ('Display Name');
  853. $w->addRule ('not empty', intl_get ('Display name may not be empty.'));
  854. $w =& $form->addWidget ('text', 'instructions');
  855. $w->alt = intl_get ('Instructions');
  856. $w->addRule ('not empty', intl_get ('Instructions may not be empty.'));
  857. $w->extra = 'size="40"';
  858. $w =& $form->addWidget ('textarea', 'value_list');
  859. $w->alt = intl_get ('Values (one-per-line)');
  860. $w->rows = 3;
  861. $w->labelPosition = 'left';
  862. $w =& $form->addWidget ('text', 'values');
  863. $w->alt = intl_get ('Retrieve values from function');
  864. $w =& $form->addWidget ('text', 'default_value');
  865. $w->alt = intl_get ('Default Value');
  866. $w =& $form->addWidget ('msubmit', 'submit_button');
  867. $b =& $w->getButton ();
  868. $b->setValues (intl_get ('Save'));
  869. $b =& $w->addButton ('cancel_button');
  870. $b->setValues (intl_get ('Cancel'));
  871. $b->extra = 'onclick="window.location.href = \'' . site_prefix () . '/index/usradm-browse-action?list=prefs\'; return false"';
  872. return $form;
  873. }
  874. /**
  875. * Generate a form for editing items in this list.
  876. *
  877. * @return object saf.MailForm object
  878. */
  879. function &getEditForm ($item) {
  880. loader_import ('saf.MailForm');
  881. $form = new MailForm;
  882. $form->action = site_prefix () . '/index/usradm-edit-pref-action';
  883. $form->error_mode = 'all';
  884. $form->addWidget ('hidden', '_list');
  885. $form->addWidget ('hidden', '_key');
  886. $w =& $form->addWidget ('text', 'pref_name');
  887. $w->alt = intl_get ('Preference Name');
  888. $w->addRule ('not empty', intl_get ('Preference name may not be empty.'));
  889. $w->setValue ($item);
  890. $w->extra = 'maxlength="32"';
  891. $w =& $form->addWidget ('text', 'alt');
  892. $w->alt = intl_get ('Display Name');
  893. $w->addRule ('not empty', intl_get ('Display name may not be empty.'));
  894. $w->setValue ($this->data[$item]['alt']);
  895. $w =& $form->addWidget ('text', 'instructions');
  896. $w->alt = intl_get ('Instructions');
  897. $w->addRule ('not empty', intl_get ('Instructions may not be empty.'));
  898. $w->extra = 'size="40"';
  899. $w->setValue ($this->data[$item]['instructions']);
  900. $w =& $form->addWidget ('textarea', 'value_list');
  901. $w->alt = intl_get ('Values (one-per-line)');
  902. $w->rows = 3;
  903. $w->labelPosition = 'left';
  904. $vals = '';
  905. foreach ($this->data[$item] as $k => $v) {
  906. if (strpos ($k, 'value ') === 0) {
  907. if ($v === '1') {
  908. $vals .= 'on' . NEWLINE;
  909. } elseif (! $v) {
  910. $vals .= 'off' . NEWLINE;
  911. } else {
  912. $vals .= $v . NEWLINE;
  913. }
  914. }
  915. }
  916. $w->setValue ($vals);
  917. $w =& $form->addWidget ('text', 'values');
  918. $w->alt = intl_get ('Retrieve values from function');
  919. $w->setValue ($this->data[$item]['values']);
  920. $w =& $form->addWidget ('text', 'default_value');
  921. $w->alt = intl_get ('Default Value');
  922. $v = $this->data[$item]['default_value'];
  923. if ($v === '1') {
  924. $w->setValue ('on');
  925. } else {
  926. $w->setValue ($v);
  927. }
  928. $w =& $form->addWidget ('msubmit', 'submit_button');
  929. $b =& $w->getButton ();
  930. $b->setValues (intl_get ('Save'));
  931. $b =& $w->addButton ('cancel_button');
  932. $b->setValues (intl_get ('Cancel'));
  933. $b->extra = 'onclick="window.location.href = \'' . site_prefix () . '/index/usradm-browse-action?list=prefs\'; return false"';
  934. return $form;
  935. }
  936. }
  937. /**
  938. * @package Session
  939. */
  940. class SessionManager_Team { // Lives in inc/conf/auth/teams/index.php
  941. /* INI Format:
  942. * [core]
  943. * disaabled = no
  944. * description = "This is the default team."
  945. */
  946. /**
  947. * File to store info.
  948. */
  949. var $file = 'inc/conf/auth/teams/index.php';
  950. /**
  951. * Parsed data from file.
  952. */
  953. var $data = array ();
  954. /**
  955. * Error message, if an error occurs.
  956. */
  957. var $error;
  958. /**
  959. * Constructor method.
  960. */
  961. function SessionManager_Team () {
  962. $this->getData ();
  963. }
  964. /**
  965. * Retrieves the data from $file and stores it in $data.
  966. */
  967. function getData () {
  968. $this->data = ini_parse ($this->file, true);
  969. }
  970. /**
  971. * Returns an array of the data.
  972. *
  973. * @return array
  974. */
  975. function getList () {
  976. return $this->data;
  977. }
  978. /**
  979. * Adds an item to $data and rewrites the INI file.
  980. *
  981. * @param string
  982. * @param boolean
  983. * @param string
  984. * @return boolean
  985. */
  986. function add ($name, $disabled, $description) {
  987. $this->data[$name] = array ('disabled' => $disabled, 'description' => $description);
  988. $r = file_overwrite ($this->file, ini_write ($this->data));
  989. if (! $r) {
  990. $this->error = 'Failed to write INI file!';
  991. }
  992. return $r;
  993. }
  994. /**
  995. * Renames an item in $data and rewrites the INI file.
  996. *
  997. * @param string
  998. * @param string
  999. * @param boolean
  1000. * @param string
  1001. * @return boolean
  1002. */
  1003. function edit ($name, $newname, $disabled, $description) {
  1004. unset ($this->data[$name]);
  1005. $this->data[$newname] = array ('disabled' => $disabled, 'description' => $description);
  1006. $r = file_overwrite ($this->file, ini_write ($this->data));
  1007. if (! $r) {
  1008. $this->error = 'Failed to write INI file!';
  1009. }
  1010. return $r;
  1011. }
  1012. /**
  1013. * Deletes an item from $data and rewrites the INI file.
  1014. *
  1015. * @param string
  1016. * @return boolean
  1017. */
  1018. function delete ($name) {
  1019. unset ($this->data[$name]);
  1020. $r = file_overwrite ($this->file, ini_write ($this->data));
  1021. if (! $r) {
  1022. $this->error = 'Failed to write INI file!';
  1023. }
  1024. return $r;
  1025. }
  1026. /**
  1027. * Generate a form for adding items to this list.
  1028. *
  1029. * @return object saf.MailForm object
  1030. */
  1031. function &getAddForm () {
  1032. loader_import ('saf.MailForm');
  1033. $form = new MailForm;
  1034. $form->action = site_prefix () . '/index/usradm-add-team-action';
  1035. $form->error_mode = 'all';
  1036. $form->addWidget ('hidden', '_list');
  1037. $w =& $form->addWidget ('text', 'name');
  1038. $w->alt = intl_get ('Name');
  1039. $w->addRule ('not empty', intl_get ('Team name may not be empty.'));
  1040. $w->extra = 'maxlength="48"';
  1041. $w =& $form->addWidget ('select', 'disabled');
  1042. $w->alt = intl_get ('Disabled');
  1043. $w->setValues (array ('yes' => intl_get ('Yes'), 'no' => intl_get ('No')));
  1044. $w->setValue ('no');
  1045. $w =& $form->addWidget ('text', 'description');
  1046. $w->alt = intl_get ('Description');
  1047. $w->addRule ('not empty', intl_get ('Description may not be empty.'));
  1048. $w->extra = 'size="40"';
  1049. $w =& $form->addWidget ('msubmit', 'submit_button');
  1050. $b =& $w->getButton ();
  1051. $b->setValues (intl_get ('Save'));
  1052. $b =& $w->addButton ('cancel_button');
  1053. $b->setValues (intl_get ('Cancel'));
  1054. $b->extra = 'onclick="window.location.href = \'' . site_prefix () . '/index/usradm-browse-action?list=teams\'; return false"';
  1055. return $form;
  1056. }
  1057. /**
  1058. * Generate a form for editing items in this list.
  1059. *
  1060. * @return object saf.MailForm object
  1061. */
  1062. function &getEditForm ($item) {
  1063. loader_import ('saf.MailForm');
  1064. $form = new MailForm;
  1065. $form->action = site_prefix () . '/index/usradm-edit-team-action';
  1066. $form->error_mode = 'all';
  1067. $form->addWidget ('hidden', '_list');
  1068. $form->addWidget ('hidden', '_key');
  1069. $w =& $form->addWidget ('info', 'name');
  1070. $w->alt = intl_get ('Name');
  1071. $w->addRule ('not empty', intl_get ('Team name may not be empty.'));
  1072. $w->setValue ($item);
  1073. $w->extra = 'maxlength="48"';
  1074. $w =& $form->addWidget ('select', 'disabled');
  1075. $w->alt = intl_get ('Disabled');
  1076. $w->setValues (array ('yes' => intl_get ('Yes'), 'no' => intl_get ('No')));
  1077. if (! $this->data[$item]['disabled']) {
  1078. $w->setValue ('no');
  1079. } else {
  1080. $w->setValue ('yes');
  1081. }
  1082. $w =& $form->addWidget ('text', 'description');
  1083. $w->alt = intl_get ('Description');
  1084. $w->addRule ('not empty', intl_get ('Description may not be empty.'));
  1085. $w->extra = 'size="40"';
  1086. $w->setValue ($this->data[$item]['description']);
  1087. $w =& $form->addWidget ('msubmit', 'submit_button');
  1088. $b =& $w->getButton ();
  1089. $b->setValues (intl_get ('Save'));
  1090. $b =& $w->addButton ('cancel_button');
  1091. $b->setValues (intl_get ('Cancel'));
  1092. $b->extra = 'onclick="window.location.href = \'' . site_prefix () . '/index/usradm-browse-action?list=teams\'; return false"';
  1093. return $form;
  1094. }
  1095. }
  1096. /**
  1097. * Handles INI files of the format:
  1098. *
  1099. * value1=
  1100. * value2=
  1101. * value3=
  1102. *
  1103. * @package Session
  1104. */
  1105. class SessionManager_Simple {
  1106. /**
  1107. * File to store info.
  1108. */
  1109. var $file;
  1110. /**
  1111. * Parsed data from file.
  1112. */
  1113. var $data = array ();
  1114. /**
  1115. * Error message, if an error occurs.
  1116. */
  1117. var $error;
  1118. /**
  1119. * Constructor method.
  1120. */
  1121. function SessionManager_Simple () {
  1122. $this->getData ();
  1123. }
  1124. /**
  1125. * Retrieves the data from $file and stores it in $data.
  1126. */
  1127. function getData () {
  1128. $this->data = ini_parse ($this->file, false);
  1129. }
  1130. /**
  1131. * Returns an array of the data.
  1132. *
  1133. * @return array
  1134. */
  1135. function getList () {
  1136. return array_keys ($this->data);
  1137. }
  1138. /**
  1139. * Adds an item to $data and rewrites the INI file.
  1140. *
  1141. * @param string
  1142. * @return boolean
  1143. */
  1144. function add ($name) {
  1145. $this->data[$name] = '';
  1146. $r = file_overwrite ($this->file, ini_write ($this->data));
  1147. if (! $r) {
  1148. $this->error = 'Failed to write INI file!';
  1149. }
  1150. return $r;
  1151. }
  1152. /**
  1153. * Renames an item in $data and rewrites the INI file.
  1154. *
  1155. * @param string
  1156. * @param string
  1157. * @return boolean
  1158. */
  1159. function edit ($name, $newname) {
  1160. unset ($this->data[$name]);
  1161. $this->data[$newname] = '';
  1162. $r = file_overwrite ($this->file, ini_write ($this->data));
  1163. if (! $r) {
  1164. $this->error = 'Failed to write INI file!';
  1165. }
  1166. return $r;
  1167. }
  1168. /**
  1169. * Deletes an item from $data and rewrites the INI file.
  1170. *
  1171. * @param string
  1172. * @return boolean
  1173. */
  1174. function delete ($name) {
  1175. unset ($this->data[$name]);
  1176. $r = file_overwrite ($this->file, ini_write ($this->data));
  1177. if (! $r) {
  1178. $this->error = 'Failed to write INI file!';
  1179. }
  1180. return $r;
  1181. }
  1182. }
  1183. /**
  1184. * @package Session
  1185. */
  1186. class SessionManager_Status extends SessionManager_Simple { // Lives in inc/conf/auth/status/index.php
  1187. /* INI Format:
  1188. * approved=
  1189. */
  1190. /**
  1191. * File to store status info.
  1192. */
  1193. var $file = 'inc/conf/auth/status/index.php';
  1194. }
  1195. /**
  1196. * @package Session
  1197. */
  1198. class SessionManager_Access extends SessionManager_Simple { // Lives in inc/conf/auth/access/index.php
  1199. /* INI Format:
  1200. * public=
  1201. */
  1202. /**
  1203. * File to store access info.
  1204. */
  1205. var $file = 'inc/conf/auth/access/index.php';
  1206. }
  1207. /**
  1208. * @package Session
  1209. */
  1210. class SessionManager_Resource extends SessionManager_Simple { // Lives in inc/conf/auth/resources/index.php
  1211. /* INI Format:
  1212. * documents=
  1213. */
  1214. /**
  1215. * File to store resource info.
  1216. */
  1217. var $file = 'inc/conf/auth/resources/index.php';
  1218. }
  1219. ?>