Changeset 1914


Ignore:
Timestamp:
01/05/10 08:37:12 (14 years ago)
Author:
amuller
Message:

Ticket #670 - Implementação de pref. obrig. por grupo

Location:
sandbox/expresso2.2
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • sandbox/expresso2.2/phpgwapi/inc/class.preferences.inc.php

    r1295 r1914  
    222222                                $this->session = array(); 
    223223                        } 
     224                        $groups = $GLOBALS['phpgw']->accounts->membership(); 
     225                        foreach($groups as $group) 
     226                                $gids .= ",".$group['account_id']; 
     227                        $account_id = (int)$this->account_id; 
     228 
    224229                        $this->db->query("SELECT * FROM phpgw_preferences" 
    225                                 . " WHERE preference_owner IN (-1,-2," . (int)$this->account_id . ')',__LINE__,__FILE__); 
     230                                . " WHERE preference_owner IN (-1,-2," . $account_id . $gids . ')',__LINE__,__FILE__); 
    226231 
    227232                        $this->forced = $this->default = $this->user = array(); 
     
    244249                                                $this->default[$app] = $value; 
    245250                                                break; 
    246                                         default:        // user 
     251                                        case $account_id: //user 
    247252                                                $this->user[$app] = $value; 
     253                                                break; 
     254                                        default: // group 
     255                                                $this->group[$app] = $value; 
    248256                                                break; 
    249257                                } 
     
    273281                                } 
    274282                        } 
     283                        // now set/force forced values for groups 
     284                        // 
     285                        foreach($this->group as $app => $values) 
     286                        { 
     287                                foreach($values as $var => $value) 
     288                                { 
     289                                        $this->data[$app][$var] = $value; 
     290                                } 
     291                        } 
     292 
    275293                        // now set/force forced values 
    276294                        // 
     
    532550                @note the user prefs for saveing are in $this->user not in $this->data, which are the effectiv prefs only 
    533551                */ 
    534                 function save_repository($update_session_info = False,$type='user') 
     552                function save_repository($update_session_info = False,$type='user',$account_id = null) 
    535553                { 
    536554                        switch($type) 
    537555                        { 
    538556                                case 'forced': 
    539                                         $account_id = -1; 
     557                                        if ($account_id == null) 
     558                                                $account_id = -1; 
    540559                                        $prefs = &$this->forced; 
    541560                                        break; 
     
    554573                        { 
    555574                                $this->db->transaction_begin(); 
    556                                 //$this->db->query("DELETE FROM phpgw_preferences WHERE preference_owner='$account_id'", 
    557                                 $this->db->query("DELETE FROM phpgw_preferences WHERE preference_owner='$account_id' and preference_app <> 'jabberit_messenger'", 
    558                                         __LINE__,__FILE__ 
    559                                 ); 
    560  
    561575                                foreach($prefs as $app => $value) 
    562576                                { 
     
    566580                                        } 
    567581                                        $this->quote($value); 
    568                                         $value = $this->db->db_addslashes(serialize($value));   // this addslashes is for the database 
     582                                        $value = $this->db->db_addslashes(serialize($value));    // this addslashes is for the database 
    569583                                        $app = $this->db->db_addslashes($app); 
    570584 
    571                                         $this->db->query($sql = "INSERT INTO phpgw_preferences" 
    572                                                 . " (preference_owner,preference_app,preference_value)" 
    573                                                 . " VALUES ($account_id,'$app','$value')",__LINE__,__FILE__); 
     585                                        $query = "SELECT (preference_owner, preference_app) FROM phpgw_preferences WHERE preference_owner = '".$account_id."' AND preference_app = '".$app."'"; 
     586 
     587                                        $this->db->query($query, __LINE__, __FILE__); 
     588 
     589                                        if(!$this->db->next_record()) 
     590                                        { 
     591                                                // Insert Db 
     592                                                $query = "INSERT INTO phpgw_preferences(preference_owner,preference_app, preference_value) ". 
     593                                                        "VALUES('".$account_id."','".$app."','".$value."')"; 
     594                                        } 
     595                                        else 
     596                                        {       
     597                                                // Update Db 
     598                                                $query = "UPDATE phpgw_preferences SET preference_value = '".$value."' WHERE ". 
     599                                                        "preference_owner = '".$account_id."' AND preference_app = '".$app."'"; 
     600                                        } 
     601                                        $this->db->query($query, __LINE__, __FILE__);                 
    574602                                } 
    575603                                $this->db->transaction_commit(); 
  • sandbox/expresso2.2/preferences/preferences.php

    r1611 r1914  
    345345        function process_array(&$repository,$array,$notifys,$prefix='') 
    346346        { 
     347                $group_id = ($_POST['group']*1);         
    347348                $_appname = check_app(); 
    348349 
     
    397398                { 
    398399                        return $error; 
    399                 } 
    400                  
    401                 $GLOBALS['phpgw']->preferences->save_repository(True,$GLOBALS['type']); 
     400                }        
     401                $GLOBALS['phpgw']->preferences->save_repository(True,$GLOBALS['type'],$group_id); 
    402402                 
    403403                return False; 
     
    590590                $t->set_var('tabs',$GLOBALS['phpgw']->common->create_tabs($tabs,$selected)); 
    591591        } 
     592        if ($GLOBALS['type'] == 'forced') 
     593        { 
     594                $select_groups = '<script src="js/config.js"></script> 
     595                                  <script src="js/connector.js"></script> 
     596                                <td>'.lang('groups').':<input type="text" value="" size="30" onkeyup="search_user(this)"> 
     597                                <span id="span_searching1"></span></td> 
     598                                <td><select name="group" id="searchu" style="width: 200px;" size="5" id="search"></td>'; 
     599                $t->set_var('select_groups',$select_groups); 
     600        } 
    592601        $t->set_var('lang_submit', lang('save')); 
    593602        $t->set_var('lang_cancel', lang('cancel')); 
  • sandbox/expresso2.2/preferences/templates/default/preferences.tpl

    r1405 r1914  
    99 {rows} 
    1010 <!-- END list --> 
     11  <tr> 
     12   {select_groups} 
     13  </tr> 
    1114  <tr height="30" valign="bottom"> 
    1215  <td align="left"> 
Note: See TracChangeset for help on using the changeset viewer.