[ghelda-devel] [45] Add plugins/Requests.php - A requests manager (per unit, per whatever, we'll see). |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/ghelda-devel Archives
]
Revision: 45
Author: odyx
Date: 2009-05-20 13:48:21 +0200 (Wed, 20 May 2009)
Log Message:
-----------
Add plugins/Requests.php - A requests manager (per unit, per whatever, we'll see).
Added Paths:
-----------
trunk/plugins/Requests.php
Added: trunk/plugins/Requests.php
===================================================================
--- trunk/plugins/Requests.php (rev 0)
+++ trunk/plugins/Requests.php 2009-05-20 11:48:21 UTC (rev 45)
@@ -0,0 +1,156 @@
+<?php
+/*
+ * Ghelda - Gestion Hiérarchisée En Ligne D'Adresses
+ * - Online Hierarchical Handling Of Adresses
+ *
+ * Copyright (C) 2008 Didier Raboud
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+define('G_REQUESTS_URL_MODE','mode');
+define('G_REQUESTS_DEFAULT_MODE','list');
+define('G_REQUESTS_ID_NEW','-1');
+define('G_REQUESTS_ID','group_id');
+
+class Requests extends Plugin {
+
+ // List of the modes
+ private $modes = array('edit','list','new','del');
+ // Actual mode
+ private $mode;
+
+ //! Constructor
+ function __construct(&$parentRef,$name)
+ {
+ $to_return = parent::__construct(&$parentRef,$name);
+ return $to_return;
+ }
+
+ function modesMenu()
+ {
+ $this->startTrad();
+ $targets['Tname'] = T_('Requests');
+ $targets['new']['name'] = T_('New');
+ $targets['list']['name'] = T_('List');
+ $this->stopTrad();
+ return $targets;
+ }
+
+ function main()
+ { $this->startTrad();
+
+ // Take the mode from the URL or take the default mode
+ $this->mode =
+ array_key_exists(G_REQUESTS_URL_MODE,$this->url->querystring)
+ ? $this->url->querystring[G_REQUESTS_URL_MODE]
+ : G_REQUESTS_DEFAULT_MODE;
+
+ // If the mode is not know, trigger an error
+ if(array_search($this->mode,$this->modes) === false) {
+ trigger_error(T_('Intrusion tentative detected: ').T_("Don't try to use undefined mode names!"), G_E_LOG);
+ return false;
+ }
+
+ // Only execute if the user is authentified
+ if($this->authH->getAuth()) {
+ // From here, we are in know mode
+ // Get the Id from a query or edit myself
+ $request_id = array_key_exists(G_REQUESTS_ID,$_GET) ? $_GET[G_REQUESTS_ID] : G_REQUESTS_ID_NEW;
+
+ switch($this->mode) {
+ case 'edit':
+ $this->m_edit($request_id,$this->fields);
+ break;
+ case 'list':
+ $this->m_list();
+ break;
+ case 'new':
+ $this->m_edit(G_REQUESTS_ID_NEW,$this->fields);
+ break;
+ case 'del':
+ $this->m_del($request_id);
+ break;
+ }
+ }
+
+ $this->stopTrad();
+ }
+
+ function functionality($funcStr,$funcArgs = '')
+ {
+ switch($funcStr) {
+ case "main":
+ $this->main();
+ break;
+ }
+ }
+
+ private function m_edit($id,&$fieldsSpec)
+ {
+ // Modification asked
+ if($_POST[$this->configH['URL']['action']] == 'change') {
+ }
+
+ $functionalityResult = $this->_parent->functionality('Requests.FieldsList');
+
+ // Go along the plugins
+ foreach($functionalityResult as $pluginName => $pFunctionalityResult){
+ $fieldsSpec[$pluginName]['type'] = 'SELECT';
+ $fieldsSpec[$pluginName]['name'] = $pFunctionalityResult['name'];
+ $fieldsSpec[$pluginName]['multiple'] = true;
+ // Go along all fields and attribute to each the name and the name only
+ foreach($pFunctionalityResult['fieldsList'] as $fieldIdentifier => $fieldSpec){
+ if( array_key_exists('noShow',$fieldSpec) ) continue;
+ $name = $fieldSpec['name'];
+ $fieldsSpec[$pluginName]['values'][$fieldIdentifier] = is_array($name) ? $name[0] : $name;
+ }
+ }
+
+ $fullFieldsSpec[$this->name] = $fieldsSpec;
+
+ // SELECT
+ // FieldsList
+ // `G_groups`.`group_id`,
+ // `G_groups`.`type`,
+ // `G_groups`.`name`,
+ // `G_people_groups`.`people_group_id`,
+ // `G_people_groups`.`group_id`,
+ // `G_people_groups`.`start_date`,
+ // `G_people_groups`.`end_date`,
+ // `G_people_groups`.`role`
+ // FROM
+ // TablesList (exhaustive)
+ // `G_people_groups`,
+ // `G_groups`
+ // WHERE
+ // Conditions (linkers)
+ // `G_people_groups`.`group_id` = `G_groups`.`group_id`
+ // AND
+ // Binders
+ // `people_id` = '1'
+ // ORDER BY
+ // Ordering
+ // `G_people_groups`.`start_date` DESC
+
+ $displayOptions['title'] = T_('New request');
+ $displayOptions['id'] = 'Requests_edit';
+ $displayOptions['command'] = T_('Create request');
+ $displayOptions['target'] = $this->url->getURL();
+ $displayOptions['action'] = 'change';
+
+ $this->output->displayFields($fullFieldsSpec,array(),$displayOptions);
+ }
+}
+?>
\ No newline at end of file