source: contrib/ProjectManager/inc/class.projectmanager_widget.inc.php @ 3594

Revision 3594, 4.3 KB checked in by afernandes, 13 years ago (diff)

Ticket #1416 - Disponibilizado o módulo ProjectManager? para a comunidade

  • Property svn:executable set to *
Line 
1<?php
2/**
3 * ProjectManager - eTemplate widgets
4 *
5 * @link http://www.egroupware.org
6 * @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
7 * @package projectmanager
8 * @copyright (c) 2005 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
9 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
10 * @version $Id: class.projectmanager_widget.inc.php 24486 2007-10-02 13:40:49Z ralfbecker $
11 */
12
13/**
14 * ProjectManager: eTemplate widgets
15 *
16 * The Select Price Widget show the pricelist of the project with pm_id=$content['pm_id']!!!
17 */
18class projectmanager_widget
19{
20        /**
21         * @var array $public_functions exported methods of this class
22         */
23        var $public_functions = array(
24                'pre_process' => True,
25        );
26        /**
27         * @var array $human_name availible extensions and there names for the editor
28         */
29        var $human_name = array(
30                'projectmanager-select'    => 'Select Project',
31                'projectmanager-pricelist' => 'Select Price',
32        );
33
34        /**
35         * Constructor of the extension
36         *
37         * @param string $ui '' for html
38         */
39        function projectmanager_widget($ui)
40        {
41                $this->ui = $ui;
42        }
43
44        /**
45         * pre-processing of the extension
46         *
47         * This function is called before the extension gets rendered
48         *
49         * @param string $name form-name of the control
50         * @param mixed &$value value / existing content, can be modified
51         * @param array &$cell array with the widget, can be modified for ui-independent widgets
52         * @param array &$readonlys names of widgets as key, to be made readonly
53         * @param mixed &$extension_data data the extension can store persisten between pre- and post-process
54         * @param object &$tmpl reference to the template we belong too
55         * @return boolean true if extra label is allowed, false otherwise
56         */
57        function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl)
58        {
59                static $pricelist = array();
60                // check if user has rights to run projectmanager
61                if (!$GLOBALS['phpgw_info']['user']['apps']['projectmanager'])
62                {
63                        $cell = $tmpl->empty_cell();
64                        $value = '';
65                        return false;
66                }
67                $extension_data['type'] = $cell['type'];
68
69                switch ($cell['type'])
70                {
71                        case 'projectmanager-select':
72                                if (!is_object($GLOBALS['boprojectmanager']))
73                                {
74                                        CreateObject('projectmanager.boprojectmanager');        // assigns itselft to $GLOBALS['boprojectmanager']
75                                }
76                                $cell['sel_options'] = $GLOBALS['boprojectmanager']->link_query('');
77                                if ($value && !isset($cell['sel_options'][$value]) && ($title = $GLOBALS['boprojectmanager']->link_title($value)))
78                                {
79                                        $cell['sel_options'][$value] = $title;
80                                }
81                                if (!$cell['help']) $cell['help'] = /*lang(*/ 'Select a project' /*)*/;
82                                break;
83
84                        case 'projectmanager-pricelist':                        // rows, pm_id-var, price-var
85                                list($rows,$pm_id_var,$price_var) = explode(',',$cell['size']);
86                                if (!$pm_id_var) $pm_id_var = 'pm_id';  // where are the pm_id(s) storered
87                                $pm_ids = $tmpl->content[$pm_id_var];
88                                $cell['sel_options'] = array();
89                                foreach((array) $pm_ids as $pm_id)
90                                {
91                                        // some caching for the pricelist, in case it's needed multiple times
92                                        if (!isset($pricelist[$pm_id]))
93                                        {
94                                                if (!is_object($this->pricelist))
95                                                {
96                                                        require_once(PHPGW_INCLUDE_ROOT.'/projectmanager/inc/class.bopricelist.inc.php');
97                                                        $this->pricelist =& new bopricelist();
98                                                }
99                                                $pricelist[$pm_id] = $this->pricelist->pricelist($pm_id);
100                                        }
101                                        if (!is_array($pricelist[$pm_id])) continue;
102
103                                        foreach($pricelist[$pm_id] as $pl_id => $label)
104                                        {
105                                                if (!isset($cell['sel_options'][$pl_id]))
106                                                {
107                                                        $cell['sel_options'][$pl_id] = $label;
108                                                }
109                                                // if pl_id already used as index, we use pl_id-price as index
110                                                elseif (preg_match('/\(([0-9.,]+)\)$/',$label,$matches) &&
111                                                                !isset($cell['sel_options'][$pl_id.'-'.$matches[1]]))
112                                                {
113                                                        $cell['sel_options'][$pl_id.'-'.$matches[1]] = $label;
114                                                }
115                                        }
116                                }
117                                // check if we have a match with pl_id & price --> use it
118                                if ($price_var && ($price = $tmpl->content[$price_var]) && isset($cell['sel_options'][$value.'-'.$price]))
119                                {
120                                        $value .= '-'.$price;
121                                }
122                                $cell['size'] = $rows;  // as the other options are not understood by the select-widget
123
124                                if (!$cell['help']) $cell['help'] = /*lang(*/ 'Select a price' /*)*/;
125                                break;
126                }
127                $cell['no_lang'] = True;
128                $cell['type'] = 'select';
129                if ($rows > 1)
130                {
131                        unset($cell['sel_options']['']);
132                }
133                return True;    // extra Label Ok
134        }
135}
Note: See TracBrowser for help on using the repository browser.