Ejemplo n.º 1
0
 function cd_save($args)
 {
     $this->add_texts('localization/', false);
     if ($args['section'] != 'cd_preferences') {
         return;
     }
     $prefs = carddav_common::get_adminsettings();
     if (isset($prefs['_GLOBAL']['hide_preferences']) && $prefs['_GLOBAL']['hide_preferences'] === TRUE) {
         return;
     }
     // update existing in DB
     $abooks = carddav_backend::get_dbrecord($_SESSION['user_id'], 'id,presetname', 'addressbooks', false, 'user_id');
     foreach ($abooks as $abook) {
         $abookid = $abook['id'];
         if (isset($_POST[$abookid . "_cd_delete"])) {
             self::delete_abook($abookid);
         } else {
             $newset = array('name' => get_input_value($abookid . "_cd_name", RCUBE_INPUT_POST), 'username' => get_input_value($abookid . "_cd_username", RCUBE_INPUT_POST, true), 'url' => get_input_value($abookid . "_cd_url", RCUBE_INPUT_POST), 'active' => isset($_POST[$abookid . '_cd_active']) ? 1 : 0, 'refresh_time' => get_input_value($abookid . "_cd_refresh_time", RCUBE_INPUT_POST));
             // only set the password if the user entered a new one
             $password = get_input_value($abookid . "_cd_password", RCUBE_INPUT_POST, true);
             if (strlen($password) > 0) {
                 $newset['password'] = $password;
             }
             // remove admin only settings
             foreach ($newset as $pref => $value) {
                 if (self::no_override($pref, $abook, $prefs)) {
                     unset($newset[$pref]);
                 }
             }
             self::update_abook($abookid, $newset);
         }
     }
     // add a new address book?
     $new = get_input_value('new_cd_name', RCUBE_INPUT_POST);
     if ((!array_key_exists('_GLOBAL', $prefs) || !$prefs['_GLOBAL']['fixed']) && strlen($new) > 0) {
         $srv = get_input_value('new_cd_url', RCUBE_INPUT_POST);
         $usr = get_input_value('new_cd_username', RCUBE_INPUT_POST, true);
         $pass = get_input_value('new_cd_password', RCUBE_INPUT_POST, true);
         $pass = self::$helper->encrypt_password($pass);
         $abname = get_input_value('new_cd_name', RCUBE_INPUT_POST);
         $discovery = new carddav_discovery();
         $srvs = $discovery->find_addressbooks($srv, $usr, $pass);
         if (is_array($srvs) && count($srvs) > 0) {
             foreach ($srvs as $srv) {
                 self::$helper->debug("ADDING ABOOK " . print_r($srv, true));
                 $this_abname = $abname;
                 if ($srv['name']) {
                     $this_abname .= ' (' . $srv['name'] . ')';
                 }
                 self::insert_abook(array('name' => $this_abname, 'username' => $usr, 'password' => $pass, 'url' => $srv['href'], 'refresh_time' => get_input_value('new_cd_refresh_time', RCUBE_INPUT_POST)));
             }
         } else {
             $args['abort'] = true;
             $args['message'] = $abname . ': ' . $this->gettext('cd_err_noabfound');
         }
     }
     return $args;
 }
Ejemplo n.º 2
0
 public static function initClass()
 {
     self::$helper = new carddav_common('DISCOVERY: ');
 }