Example #1
0
 /**
  *  validate html form 
  *
  *  @param array $errors    array with error messages
  *  @return bool            TRUE if given values of form are OK, FALSE otherwise
  */
 function validate_form(&$errors)
 {
     global $lang_str, $data, $config;
     if ($this->action['action'] == "insert") {
         if (!$this->validate_number_of_entries($errors)) {
             return false;
         }
         return true;
     }
     if ($this->action['action'] == 'create') {
         if (!$this->validate_number_of_entries($errors)) {
             return false;
         }
     }
     if ($this->action['action'] == 'edit' or $this->action['action'] == 'update' or $this->action['action'] == 'delete') {
         if (!$this->is_edit_allowed($this->edit['un'], $this->edit['did'])) {
             $errors[] = $lang_str['err_uri_modify_not_permited'];
             return false;
         }
     }
     if ($this->action['action'] == 'edit' or $this->action['action'] == 'delete') {
         return true;
     }
     $form_ok = true;
     if (false === parent::validate_form($errors)) {
         $form_ok = false;
     }
     if (!isset($_POST['uri_is_canon'])) {
         $_POST['uri_is_canon'] = 0;
     }
     if (!$this->check_did($_POST['uri_did'])) {
         $d =& Domain::singleton();
         $errors[] = "Operation failed: You haven't access to domain: " . $d->get_domain_name($did);
         return false;
     }
     if ($_POST['uri_is_canon']) {
         if (!$this->check_canon_flag()) {
             return false;
         }
     }
     /* Check wheteher URI is unique */
     $opt = array();
     $opt['filter']['username'] = new Filter("username", $_POST['uri_un'], "=", false, false);
     $opt['filter']['did'] = new Filter("did", $_POST['uri_did'], "=", false, false);
     $opt['filter']['scheme'] = new Filter("scheme", "sip", "=", false, false);
     if (false === ($dups = $data->get_uris(null, $opt))) {
         return false;
     }
     if ($dups) {
         $dup = reset($dups);
         if ($this->action['action'] == "update" and count($dups) == 1 and $dup->username == $this->edit_uri->username and $dup->did == $this->edit_uri->did and $dup->scheme == $this->edit_uri->scheme and $dup->uid == $this->edit_uri->uid) {
         } else {
             $errors[] = $lang_str['err_ri_dup'];
             $form_ok = false;
         }
     }
     return $form_ok;
 }
Example #2
0
 function validate_form(&$errors)
 {
     global $lang_str, $data;
     if (false === parent::validate_form($errors)) {
         return false;
     }
     $did = $_POST['al_domain'];
     if (!$this->check_did($did)) {
         $d =& Domain::singleton();
         $errors[] = "You haven't access to domain which you selected: " . $d->get_domain_name($did);
         return false;
     }
     // check if admin has parmission to changed URI and if has not, return flase
     if ($_POST['al_id_d'] != "" and !$this->check_did($_POST['al_id_d'])) {
         $errors[] = "Can not update, you have not access to this URI";
         return false;
     }
     if (!empty($_POST['al_is_canon'])) {
         // chenck if cannonical flag in other URI may be cleared
         $uri_handler =& URIs::singleton($this->user_id->get_uid());
         if (false === ($uris = $uri_handler->get_URIs())) {
             return false;
         }
         foreach ($uris as $k => $v) {
             if ($v->is_canonical() and !$this->check_did($v->get_did())) {
                 $errors[] = $lang_str['err_canon_uri_exists'];
                 return false;
             }
         }
     }
     return true;
 }