source: branches/2.5/admin/inc/class.uiconfig.inc.php @ 7982

Revision 7982, 18.3 KB checked in by douglas, 11 years ago (diff)

Ticket #3378 - Importação automatica de eventos nos participantes

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /**************************************************************************\
3  * eGroupWare - Admin config                                                *
4  * Written by Miles Lott <milosch@phpwhere.org>                             *
5  * http://www.egroupware.org                                                *
6  * --------------------------------------------                             *
7  *  This program is free software; you can redistribute it and/or modify it *
8  *  under the terms of the GNU General Public License as published by the   *
9  *  Free Software Foundation; either version 2 of the License, or (at your  *
10  *  option) any later version.                                              *
11  \**************************************************************************/
12
13require_once('prototype/api/config.php');
14use prototype\api\Config as Config;
15
16        class uiconfig
17        {
18                var $public_functions = array('index' => True);
19
20                function index()
21                {
22                        if ($GLOBALS['phpgw']->acl->check('site_config_access',1,'admin'))
23                        {
24                                $GLOBALS['phpgw']->redirect_link('/index.php');
25                        }
26
27                        if(get_magic_quotes_gpc() && is_array($_POST['newsettings']))
28                        {
29                                $_POST['newsettings'] = array_map("stripslashes", $_POST['newsettings']);
30                        }
31                       
32                        switch($_GET['appname'])
33                        {
34                                case 'admin':
35                                case 'addressbook':
36                                case 'calendar':
37                                case 'email':
38                                case 'instant_messenger':
39                                case 'jabberit_messenger':
40                                case 'nntp':
41                                        /*
42                                        Other special apps can go here for now, e.g.:
43                                        case 'bogusappname':
44                                        */
45                                        $appname = $_GET['appname'];
46                                        $config_appname = 'phpgwapi';
47                                        break;
48                                case 'phpgwapi':
49                                case '':
50                                        /* This keeps the admin from getting into what is a setup-only config */
51                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
52                                        break;
53                                default:
54                                        $appname = $_GET['appname'];
55                                        $config_appname = (isset($_GET['config']) && $_GET['config']) ? $_GET['config'] : $appname ;
56                                        break;
57                        }
58
59                        $t = CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir($appname));
60                        $t->set_unknowns('keep');
61                        $t->set_file(array('config' => 'config.tpl'));
62                        $t->set_block('config','header','header');
63                        $t->set_block('config','body','body');
64                        $t->set_block('config','footer','footer');
65
66                        $c = CreateObject('phpgwapi.config',$config_appname);
67                        $c->read_repository();
68
69                        if ($c->config_data)
70                        {
71                                $current_config = $c->config_data;
72                        }
73       
74                if($appname === "expressoCalendar"){
75 
76            if($config_appname == 'expressoCalendar' )
77            {
78                $t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname));
79 
80            };
81 
82            if($_POST['newsettings']['expressoCalendar_autoImportCalendars'] == 'true')
83            {
84                $db = $GLOBALS['phpgw']->db;
85                $calendars = array();
86                $db->query('SELECT calendar_signature.user_uidnumber as "user",calendar.id as "calendar" FROM calendar,calendar_signature WHERE calendar.id = calendar_signature.calendar_id AND calendar.type = 0 AND calendar_signature.is_owner = 1 AND (SELECT id from module_preference WHERE user_uidnumber = calendar_signature.user_uidnumber AND module_preference.module = \'expressoCalendar\' AND module_preference.name = \'dafaultImportCalendar\'  ) IS NULL');
87                while( $db->next_record() )
88                {
89                    $calendars[] = $db->row();
90                }
91 
92                foreach($calendars as $v)
93                {
94                    $db->query('INSERT INTO module_preference ("user_uidnumber","value","name","module") VALUES ( \''.$v['user'].'\' , \''.$v['calendar'].'\',\'dafaultImportCalendar\' , \'expressoCalendar\')');
95                }
96            }
97 
98                        if (isset($_POST['migration']) && ($_POST['migration']  == "true")){
99                       
100                                require_once dirname(__FILE__ )."/../../expressoCalendar/inc/class.ui_migration.inc.php";
101
102                                $migratrion = new Migra();
103                                $migratrion->calendar();
104                        }
105 
106                }
107
108                        if ($_POST['cancel'] || $_POST['submit'] && $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin'))
109                        {
110                                $GLOBALS['phpgw']->redirect_link('/admin/index.php');
111                        }
112
113                        if ($_POST['submit'])
114                        {
115                                /* Load hook file with functions to validate each config (one/none/all) */
116                                $GLOBALS['phpgw']->hooks->single('config_validate',$appname);
117                               
118                                if (!isset($_POST['newsettings']['cc_allow_details'])) {
119                                        $_POST['newsettings']['cc_allow_details'] = "false";
120                                }
121
122                                foreach($_POST['newsettings'] as $key => $config)
123                                {
124                                       
125                                        if ($config) 
126                                        {                                                                                                                                                                                 // Código adicionado 
127                                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && (function_exists($key) || function_exists(substr($key,0,strrpos($key,'_')))) )
128                                                {
129                                                        if(function_exists(substr($key,0,strrpos($key,'_'))))
130                                {
131                                call_user_func(substr($key,0,strrpos($key,'_')), $config);
132                                }
133                                else
134                                {
135                                call_user_func($key,&$config);
136                                }
137
138                                if($GLOBALS['config_error'])
139                                                        {
140                                                                $errors = lang($GLOBALS['config_error']) . '&nbsp;';
141                                                                $GLOBALS['config_error'] = False;
142                                                        }
143                                                        else
144                                                        {
145                                                                $c->config_data[$key] = $config;
146                                                        }
147                                                }
148                                                else
149                                                {
150                                                        $c->config_data[$key] = $config;
151                                                }
152                                        }
153                                        else
154                                        {
155                                                /* don't erase passwords, since we also don't print them */
156                                                if(!preg_match('/passwd/',$key) && !preg_match('/password/',$key) && !preg_match('/root_pw/',$key) && !preg_match('/pw/',$key))
157                                                {
158                                                        unset($c->config_data[$key]);
159                                                }
160                                        }
161                                }
162                                if($GLOBALS['phpgw_info']['server']['found_validation_hook'] && function_exists('final_validation'))
163                                {
164                                        final_validation($c->config_data);
165                                        if($GLOBALS['config_error'])
166                                        {
167                                                $errors .= lang($GLOBALS['config_error']) . '&nbsp;';
168                                                $GLOBALS['config_error'] = False;
169                                        }
170                                        unset($GLOBALS['phpgw_info']['server']['found_validation_hook']);
171                                }
172
173                                $c->save_repository();
174
175                                if(!$errors)
176                                {
177                                        $GLOBALS['phpgw']->redirect_link('/admin/index.php');
178                                }
179                        }
180
181                        if($errors)
182                        {
183                                $t->set_var('error',lang('Error') . ': ' . $errors);
184                                $t->set_var('th_err','#FF8888');
185                                unset($errors);
186                                unset($GLOBALS['config_error']);
187                        }
188                        else
189                        {
190                                $t->set_var('error','');
191                                $t->set_var('th_err',$GLOBALS['phpgw_info']['theme']['th_bg']);
192                        }
193
194                        if(!@is_object($GLOBALS['phpgw']->js))
195                        {
196                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
197                        }
198                        $GLOBALS['phpgw']->js->validate_file('jscode','openwindow','admin');
199
200                        $GLOBALS['phpgw']->common->phpgw_header();
201                        echo parse_navbar();
202
203                       
204                        $campos = '';
205                        $checked_box = array();
206                        $i = 0;
207                       
208                        if($appname=="contactcenter")
209                        {
210                               
211                                foreach ($c->config_data as $key => $config)
212                                {               
213                                        $parts = explode('_', $key);
214                        if (is_numeric($parts[3]) && $parts[1]=='attribute')
215                        {
216                        $fields[$parts[3]][$key] = $config;
217                        }
218                       
219                       
220                        if($key == 'cc_allow_details') {
221                                $checkedCoisa = 'value="details"';
222                                if ($config=='true') {
223                                        $checkedCoisa = 'value="details" checked="checked"';
224                                }
225                        }                       
226                                }
227       
228                                $campos_vazio = true;
229                                $campos = "
230                                                <input type=\"hidden\" id=\"textHidden\" value=\"".lang('Text')."\" />
231                                                <input type=\"hidden\" id=\"multitextHidden\" value=\"".lang('Multivalued')."\" />
232                                                <input type=\"hidden\" id=\"yesHidden\" value=\"".lang('Yes')."\" />
233                                                <input type=\"hidden\" id=\"noHidden\" value=\"".lang('No')."\" />
234                                                <input type=\"hidden\" id=\"deleteHidden\" value=\"".lang('Delete')."\" />
235                                                <table id=\"cc_newconf\" name=\"cc_newconf\" class=\"cc_attribute\">
236                                                   <tbody id=\"cc_newconftable\" name=\"cc_newconftable\">
237                                                        <tr>
238                                                                <td align=\"center\" style=\"width:170px;\">" . lang('Name')               . "</td>
239                                                                <td align=\"center\" style=\"width:170px;\">" . lang('Corresponding LDAP') . "</td>
240                                                                <td align=\"center\" style=\"width:100px; margin: 0px 0px 0px 8px;\">" . lang('Type')               . "</td>
241                                                                <td align=\"center\" style=\"width:80px; margin: 0px 16px;\">" . lang('Searchable')         . "</td>
242                                                                <td align=\"center\" style=\"width: 15px;\">
243                                                        </tr>";
244               
245                        foreach ($fields as $i => $line)
246                        {
247                                        if ($line["cc_attribute_name_$i"] != '' && $line["cc_attribute_ldapname_$i"] != '') {
248                                                $campos_vazio  = false;
249                        $selectedText  = $line["cc_attribute_type_$i"] == 'text' ? 'selected="selected"' : '';
250                        $selectedTMult = $line["cc_attribute_type_$i"] == 'multivalues' ? 'selected="selected"' : '';
251                                                $selectedYes   = $line["cc_attribute_searchable_$i"] == 'true'  ? 'selected="selected"' : '';
252                                                $selectedNo    = $line["cc_attribute_searchable_$i"] == 'false' ? 'selected="selected"' : '';
253
254                                               
255                                $campos = $campos . "
256                                                                <tr>
257                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_name_" . $i . "]\" value=\"".$line["cc_attribute_name_$i"]."\" style=\"width:170px;\"></input></td>
258                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_ldapname_" . $i . "]\" value=\"".$line["cc_attribute_ldapname_$i"]."\" style=\"width:170px;\"></input></td>
259                                                                        <td><select name=\"newsettings[cc_attribute_type_" . $i . "]\" style=\"width:86px; margin: 0px 0px 0px 8px;\">
260                                                                                        <option value=\"text\" $selectedText>" . lang('Text') . "</option>
261                                                                                        <option value=\"multivalues\" $selectedTMult>" . lang('Multivalued') ."</option>
262                                                                        </select></td>
263                                                                        <td><select name=\"newsettings[cc_attribute_searchable_$i]\" style=\"margin: 0px 16px;\">
264                                                                                        <option value=\"true\" $selectedYes>" . lang('Yes') . "</option>
265                                                                                        <option value=\"false\" $selectedNo>" . lang('No') . "</option>
266                                                                        </select></td>
267                                                                        <td><img src=\"contactcenter/templates/default/images/cc_x.png\" alt=\"". lang('Delete') . "\" title=\"". lang('Delete') ."\" style=\"width: 15px; height: 14px; cursor: pointer; position: relative; top: 3px;\" onclick=\"javascript:cc_attribute_delete(this)\"></img></td> 
268                                                                </tr>";
269                        }
270                        }
271               
272                            if ($campos_vazio)
273                        {
274                                        $campos .= "<tr>
275                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_name_0]\" value=\"\" style=\"width:170px;\"/> </td>
276                                                                        <td><input type=\"text\" name=\"newsettings[cc_attribute_ldapname_0]\" value=\"\" style=\"width:170px;\"/> </td>
277                                                                        <td><select name=\"newsettings[cc_attribute_type_0]\" style=\"width:86px; margin: 0px 0px 0px 8px;\">
278                                        <option value=\"text\">" . lang('Text') . "</option>
279                                        <option value=\"multivalues\">" . lang('Multivalued') . "</option>
280                                                                        </select></td>
281                                                                        <td><select name=\"newsettings[cc_attribute_searchable_0]\" style=\"margin: 0px 16px;\">
282                                        <option value=\"true\">" . lang('Yes') . "</option>
283                                        <option value=\"false\" selected=\"selected\">" . lang('No') . "</option>
284                                                                        </select></td>
285                                                                        <td><img src=\"contactcenter/templates/default/images/cc_x.png\" alt=\"". lang('Delete') ."\" title=\"". lang('Delete') ."\" style=\"width: 15px; height: 14px; cursor: pointer; position: relative; top: 3px;\" onclick=\"javascript:cc_attribute_delete(this)\"/></td>
286                                                                </tr>";                         
287                        }
288                        $campos = $campos . "</tbody></table>";
289                       
290                        $t->set_var('lang_add_button', lang('Add'));
291                                $t->set_var('lang_cc_Set_details_attributes',   lang('Details on the Global Catalog Address'));
292                        $t->set_var('lang_cc_Allow_view_details_label', lang('Enable display of contact details for the Global Catalog'));                             
293                        $t->set_var('attribute_fields', $campos);               
294                        $t->set_var('cc_config_js', $GLOBALS['phpgw_info']['server']['webserver_url'] . '/contactcenter/js/cc_config.js');
295                        $t->set_var('cc_allow_view_details_value', $checkedCoisa);
296                        }
297               
298                       
299                        if($appname=="expressoAdmin1_2") {
300                                /* Varre a pasta inc do admin do expresso procurando scripts de geração de login automático
301                                   (classes com nomes iniciados pela string 'login', procedida da string '_' mais o nome
302                                   do algoritmo.
303                                */
304                               
305                                $dir = $GLOBALS['phpgw']->common->get_app_dir($appname) . "/inc";
306                                $options = ' ';
307                                if (is_dir($dir))
308                                {
309                                        if ($dh = opendir($dir))
310                                        {
311                                                while (($file = readdir($dh)) !== false)
312                                                {
313                                                        $temp = explode(".",$file);
314                                                        if( (substr($temp[1],0,5) =='login') && ($temp[0] == 'class') )
315                                                        {
316                                                                $options .= "<option value='".$temp[1]."'";
317                                                                if($current_config['expressoAdmin_loginGenScript'] == $temp[1])
318                                                                        $options .= " selected";
319                                                                $options .= ">" . ucwords(str_replace("_"," ",substr($temp[1],6))) . "</option>";
320                                                        }                               
321                                                }
322                                                closedir($dh);
323                                        }
324                                }
325                               
326                                $t->set_var('rows_login_generator',$options);
327                        }               
328                       
329                        if($appname=="admin") {                                                 
330                                /*
331                                 * New CKEditor to agree term
332                                 */
333                                $content = isset($GLOBALS['phpgw_info']['server']['agree_term']) ? $GLOBALS['phpgw_info']['server']['agree_term'] : '';
334                                $ckeditor = '<script type="text/javascript" src="./library/ckeditor/ckeditor.js"></script>
335                                                        <textarea cols="80" id="newsettings[agree_term]" name="newsettings[agree_term]" rows="10">' . $content . '</textarea>
336                                                        <script type="text/javascript"> CKEDITOR.replace( \'newsettings[agree_term]\',{
337                                                                removePlugins : \'elementspath\',
338                                                                skin : \'office2003\',
339                                                                toolbar : [["Source","Preview","-","Cut","Copy","Paste","-","Print",
340                                                                "Undo","Redo","-","Find","Replace","-","SelectAll" ],
341                                                                ["Table","HorizontalRule","SpecialChar","PageBreak","-","Bold",
342                                                                "Italic","Underline","Strike","-","Subscript","Superscript",
343                                                                "NumberedList","BulletedList","-","Outdent","Indent","Blockquote",
344                                                                "JustifyLeft","JustifyCenter","JustifyRight","JustifyBlock",
345                                                                "Link", "TextColor","BGColor","Maximize"],
346                                                                ["Styles","Format","Font","FontSize"]]
347                                                        });</script>';
348                                $t->set_var('agree_term_input',$ckeditor);
349                        }
350                        $t->set_var('title',lang('Site Configuration'));
351                        $t->set_var('action_url',$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname));
352                        $t->set_var('th_bg',     $GLOBALS['phpgw_info']['theme']['th_bg']);
353                        $t->set_var('th_text',   $GLOBALS['phpgw_info']['theme']['th_text']);
354                        $t->set_var('row_on',    $GLOBALS['phpgw_info']['theme']['row_on']);
355                        $t->set_var('row_off',   $GLOBALS['phpgw_info']['theme']['row_off']);
356                        $t->set_var('php_upload_limit',str_replace('M','',ini_get('upload_max_filesize')));
357                        $t->pparse('out','header');
358
359                        $vars = $t->get_undefined('body');
360
361                        $GLOBALS['phpgw']->hooks->single('config',$appname);
362                       
363                        /* Seta o valor padrão para a configuração de número máximo de marcadores */
364                        $current_config['expressoMail_limit_labels'] = (isset($current_config['expressoMail_limit_labels']) && !!$current_config['expressoMail_limit_labels'] ) ? $current_config['expressoMail_limit_labels'] : 20;
365                        //Pegar os todos os Atributos LDAP mapeados no arquivo user.ini
366                        $map = Config::get('user', 'OpenLDAP.mapping');
367                        $validate = false;     
368                        $options = "<option value=''>".lang('None')."</option>";
369                        foreach($map as $value){
370                                $options .= "<option value='".$value."'";
371                                if($current_config['expressoMail_ldap_identifier_recipient'] == $value){
372                                        $validate = true;
373                                        $options .= " selected='selected'";
374                                }
375                                $options .= ">". $value . "</option>";
376                        }
377
378                        if(!$validate){
379                                // Limpa Atributo LDAP do banco de dados caso a atribuição não exista mais.     
380                                $db = '';
381                                $db = $db ? $db : $GLOBALS['phpgw']->db;        // this is to allow setup to set the db
382                                $db->query("DELETE FROM phpgw_config WHERE config_app = '".$appname."' AND config_name = 'expressoMail_ldap_identifier_recipient'");
383                        }
384                        /* Recupera o número mínimo de marcadores que pode ser definido */
385                        $db = '';
386                        $db = $db ? $db : $GLOBALS['phpgw']->db;        // this is to allow setup to set the db
387                        $db->query("SELECT max(slot) as slot from expressomail_label",__LINE__,__FILE__);
388                        while( $db->next_record() )
389                        {
390                                $cont_labels = $db->f('slot');
391                        }
392
393                        foreach($vars as $value)
394                        {
395                                $valarray = explode('_',$value);
396                                $type = array_shift($valarray);
397                                $newval = implode(' ',$valarray);
398                                switch ($type)
399                                {
400                                        case 'lang':
401                                                $t->set_var($value,lang($newval));
402                                                break;
403                                        case 'value':
404                                                $newval = str_replace(' ','_',$newval);
405                                                /* Don't show passwords in the form */
406                                                if(preg_match('/passwd/',$value) || preg_match('/password/',$value) || preg_match('/root_pw/',$value))
407                                                {
408                                                        $t->set_var($value,'');
409                                                }
410                                                else
411                                                {
412                                                        $t->set_var($value,htmlspecialchars($current_config[$newval]));
413                                                }
414                                                break;
415                                        /*
416                                        case 'checked':
417                                                $newval = str_replace(' ','_',$newval);
418                                                if ($current_config[$newval])
419                                                {
420                                                        $t->set_var($value,' checked');
421                                                }
422                                                else
423                                                {
424                                                        $t->set_var($value,'');
425                                                }
426                                                break;
427                                        */
428                                        case 'selected':
429                                                $configs = array();
430                                                $config  = '';
431                                                $newvals = explode(' ',$newval);
432                                                $setting = end($newvals);
433                                                for ($i=0;$i<(count($newvals) - 1); ++$i)
434                                                {
435                                                        $configs[] = $newvals[$i];
436                                                }
437                                                $config = implode('_',$configs);
438                                                /* echo $config . '=' . $current_config[$config]; */
439                                                if ($current_config[$config] == $setting)
440                                                {
441                                                        $t->set_var($value,' selected');
442                                                }
443                                                else
444                                                {
445                                                        $t->set_var($value,'');
446                                                }
447                                                break;
448                                        case 'hook':
449                                                $newval = str_replace(' ','_',$newval);
450                                                if(function_exists($newval))
451                                                {
452                                                        $t->set_var($value,$newval($current_config));
453                                                }
454                                                else
455                                                {
456                                                        $t->set_var($value,'');
457                                                }
458                                                break;
459                                        default:
460                                        $t->set_var($value,'');
461                                        break;
462                                }
463                        }
464
465                        $t->set_var('min_labels',$cont_labels);
466                       
467                        $t->set_var('rows_ldap_identifier',$options);
468                        $t->pfp('out','body');
469
470                        $t->set_var('lang_submit', $GLOBALS['phpgw']->acl->check('site_config_access',2,'admin') ? lang('Cancel') : lang('Save'));
471                        $t->set_var('lang_cancel', lang('Cancel'));
472                        $t->pfp('out','footer');
473                }
474        }
475?>
Note: See TracBrowser for help on using the repository browser.