Esempio n. 1
0
 /**
  * insert a new user to database
  * @param $name_values_array array array containing name-values of record
  * @return bool indicates if user has been inserted
  */
 function insert($name_values_array)
 {
     global $user_list_permissions;
     $user_name = $name_values_array[USER_NAME_FIELD_NAME];
     $is_admin = $name_values_array[USER_IS_ADMIN_FIELD_NAME];
     $this->_log->trace("insert user (name=" . $user_name . ")");
     if (strlen($name_values_array[USER_PW_FIELD_NAME]) > 0) {
         $this->_log->debug("found a password");
         $name_values_array[USER_PW_FIELD_NAME] = md5($name_values_array[USER_PW_FIELD_NAME]);
     } else {
         $this->_log->error("could not find a password");
         return FALSE;
     }
     # if user is admin then user must also be able to create lists and users
     if (array_key_exists(USER_IS_ADMIN_FIELD_NAME, $name_values_array) == TRUE) {
         if ($name_values_array[USER_IS_ADMIN_FIELD_NAME] == 1) {
             $name_values_array[USER_CAN_CREATE_LIST_FIELD_NAME] = 1;
             $name_values_array[USER_CAN_CREATE_USER_FIELD_NAME] = 1;
         }
     }
     # if user is able to create users then user must also be able to create lists
     if (array_key_exists(USER_CAN_CREATE_USER_FIELD_NAME, $name_values_array) == TRUE) {
         if ($name_values_array[USER_CAN_CREATE_USER_FIELD_NAME] == 1) {
             $name_values_array[USER_CAN_CREATE_LIST_FIELD_NAME] = 1;
         }
     }
     if ($this->exists($user_name)) {
         $this->_handle_error("user already exists", "ERROR_DUPLICATE_USER_NAME");
         return FALSE;
     }
     if (parent::insert($name_values_array) == FALSE) {
         return FALSE;
     }
     if ($user_list_permissions->insert_list_permissions_new_user($user_name, $is_admin) == FALSE) {
         # copy error strings from user_list_permissions
         $this->error_message_str = $user_list_permissions->get_error_message_str();
         $this->error_log_str = $user_list_permissions->get_error_log_str();
         $this->error_str = $user_list_permissions->get_error_str();
         return FALSE;
     }
     $this->_log->info("user added (name=" . $user_name . ")");
     return TRUE;
 }
 /**
  * add new ListTableDescription object to database
  * @param array $name_values_array values of new ListTableDescription
  * @return bool indicates if ListTableDescription has been added
  */
 function insert($name_values_array)
 {
     $title = $name_values_array[LISTTABLEDESCRIPTION_TITLE_FIELD_NAME];
     $this->_log->trace("inserting ListTableDescription (title=" . $title . ")");
     $record = parent::select_record(LISTTABLEDESCRIPTION_TITLE_FIELD_NAME . "='" . $title . "'");
     if (count($record) > 0) {
         $this->_handle_error("this is a duplicate list", "ERROR_DUPLICATE_LIST_NAME");
         return FALSE;
     }
     # convert value
     if (array_key_exists(LISTTABLEDESCRIPTION_DEFINITION_FIELD_NAME, $name_values_array) == TRUE) {
         $name_values_array[LISTTABLEDESCRIPTION_DEFINITION_FIELD_NAME] = $this->_json->encode($name_values_array[LISTTABLEDESCRIPTION_DEFINITION_FIELD_NAME]);
     }
     if (parent::insert($name_values_array) == 0) {
         return FALSE;
     }
     if ($this->_user_list_permissions->insert_list_permissions_new_list($title) == FALSE) {
         # copy error strings from user_list_permissions
         $this->error_message_str = $this->_user_list_permissions->get_error_message_str();
         $this->error_log_str = $this->_user_list_permissions->get_error_log_str();
         $this->error_str = $this->_user_list_permissions->get_error_str();
         return FALSE;
     }
     $this->_log->trace("inserted ListTableDescription (title=" . $title . ")");
     return TRUE;
 }
Esempio n. 3
0
 /**
  * add a new record to database
  * @param $name_values_array array array containing name-values of the ListTableItem
  * @return bool indicates if new record was added
  */
 function insert($name_values)
 {
     $db_field_names = array_keys($name_values);
     $all_notes_array = array();
     $all_attachments_array = array();
     $this->_log->trace("inserting record into ListTable");
     foreach ($db_field_names as $db_field_name) {
         global $list_table_description;
         $notes_array = array();
         $field_type = $this->fields[$db_field_name][1];
         $value = $name_values[$db_field_name];
         $this->_log->debug("processing (db_field_name={$db_field_name}, field_type={$field_type})");
         # insert all notes one by one
         if ($field_type == FIELD_TYPE_DEFINITION_NOTES_FIELD) {
             foreach ($value as $note) {
                 if ($note[1] == "") {
                     $this->_log->debug("found an empty note (field=" . $db_field_name . ")");
                 } else {
                     array_push($notes_array, array($db_field_name, $note[1]));
                 }
             }
             $name_values[$db_field_name] = count($notes_array);
             array_push($all_notes_array, $notes_array);
         }
         if ($field_type == FIELD_TYPE_DEFINITION_ATTACHMENTS) {
             $all_attachments_array = $value;
             # there is always 1 empty attachment present
             $num_of_attachments = count($all_attachments_array) - 1;
             $name_values[$db_field_name] = $num_of_attachments;
             $this->_log->debug("found " . $num_of_attachments . " attachments");
         }
     }
     $new_record_id = parent::insert($name_values);
     if ($new_record_id == 0) {
         return 0;
     }
     # insert notes
     foreach ($all_notes_array as $notes_array) {
         foreach ($notes_array as $note_array) {
             if ($this->_list_table_note->insert($new_record_id, $note_array[0], $note_array[1]) == 0) {
                 # copy error strings from _list_table_note
                 $this->error_message_str = $this->_list_table_note->get_error_message_str();
                 $this->error_log_str = $this->_list_table_note->get_error_log_str();
                 $this->error_str = $this->_list_table_note->get_error_str();
                 return 0;
             }
         }
     }
     # insert attachments
     foreach ($all_attachments_array as $attachment) {
         $attachment_str = $attachment[1];
         $attachment_array = explode('|', $attachment_str);
         $tmp_file_name = $attachment_array[0];
         # do nothing with the empty array
         if ($tmp_file_name == LISTTABLEATTACHMENT_EMPTY_ATTACHMENT) {
             $this->_log->debug("found the empty attachment");
         } else {
             if ($this->_list_table_attachment->insert($new_record_id, $attachment[0], $attachment[1]) == FALSE) {
                 # copy error strings from _list_table_attachment
                 $this->error_message_str = $this->_list_table_attachment->get_error_message_str();
                 $this->error_log_str = $this->_list_table_attachment->get_error_log_str();
                 $this->error_str = $this->_list_table_attachment->get_error_str();
                 return 0;
             }
         }
     }
     # update list table description
     if ($this->_update_list_table_description_statistics() == FALSE) {
         return 0;
     }
     # also update creator modifier array
     $record = $this->_get_list_table_description_record($this->list_title);
     if (count($record) == 0) {
         return 0;
     }
     $this->_log->trace("inserted record into ListTable");
     return $new_record_id;
 }