Esempio n. 1
0
 /**
  * Event function to update the organization data
  * @param object $evctl
  */
 public function eventEditRecord(EventControler $evctl)
 {
     $id_entity = (int) $evctl->sqrecord;
     if ($id_entity > 0 && true === $_SESSION["do_crm_action_permission"]->action_permitted('edit', 4, (int) $evctl->sqrecord)) {
         $obj = $this->getId($id_entity);
         $obj = (object) $obj;
         // convert the data array to Object
         $do_process_plugins = new CRMPluginProcessor();
         // process before update plugin. If any error is raised display that.
         $do_process_plugins->process_action_plugins((int) $evctl->idmodule, $evctl, 3, $id_entity, $obj);
         if (strlen($do_process_plugins->get_error()) > 2) {
             $_SESSION["do_crm_messages"]->set_message('error', $do_process_plugins->get_error());
             $next_page = NavigationControl::getNavigationLink($evctl->module, "edit");
             $dis = new Display($next_page);
             $dis->addParam("sqrecord", $id_entity);
             if ($evctl->return_page != '') {
                 $dis->addParam("return_page", $evctl->return_page);
             }
             $evctl->setDisplayNext($dis);
         } else {
             $do_crm_fields = new CRMFields();
             //$do_crm_fields->get_field_information_by_module((int)$evctl->idmodule);
             $crm_fields = $do_crm_fields->get_field_information_by_module_as_array((int) $evctl->idmodule);
             $table_entity = 'contacts';
             $table_entity_address = 'contacts_address';
             $table_entity_custom = 'contacts_custom_fld';
             $table_entity_to_grp = 'cnt_to_grp_rel';
             $entity_data_array = array();
             $custom_data_array = array();
             $addr_data_array = array();
             $assigned_to_as_group = false;
             foreach ($crm_fields as $crm_fields) {
                 $field_name = $crm_fields["field_name"];
                 $field_value = $do_crm_fields->convert_field_value_onsave($crm_fields, $evctl, 'edit');
                 if (is_array($field_value) && count($field_value) > 0) {
                     if ($field_value["field_type"] == 15) {
                         $field_name = 'iduser';
                         $value = $field_value["value"];
                         $assigned_to_as_group = $field_value["assigned_to_as_group"];
                         $group_id = $field_value["group_id"];
                     } elseif ($field_value["field_type"] == 12) {
                         $value = $field_value["name"];
                         $avatar_array[] = $field_value;
                     }
                 } else {
                     $value = $field_value;
                 }
                 if ($crm_fields["table_name"] == $table_entity && $crm_fields["idblock"] > 0) {
                     $entity_data_array[$field_name] = $value;
                 }
                 if ($crm_fields["table_name"] == $table_entity_address && $crm_fields["idblock"] > 0) {
                     $addr_data_array[$field_name] = $value;
                 }
                 if ($crm_fields["table_name"] == $table_entity_custom && $crm_fields["idblock"] > 0) {
                     $custom_data_array[$field_name] = $value;
                 }
             }
             $this->update(array($this->primary_key => $id_entity), $table_entity, $entity_data_array);
             //updating the last_modified,last_modified_by
             $q_upd = "\n\t\t\t\tupdate `" . $this->getTable() . "` set \n\t\t\t\t`last_modified` = ? ,\n\t\t\t\t`last_modified_by` = ? \n\t\t\t\twhere `" . $this->primary_key . "` = ?";
             $this->query($q_upd, array(date("Y-m-d H:i:s"), $_SESSION["do_user"]->iduser, $id_entity));
             if (count($custom_data_array) > 0) {
                 $this->update(array($this->primary_key => $id_entity), $table_entity_custom, $custom_data_array);
             }
             if (count($addr_data_array) > 0) {
                 $this->update(array($this->primary_key => $id_entity), $table_entity_address, $addr_data_array);
             }
             if ($assigned_to_as_group === false) {
                 $qry_grp_rel = "DELETE from `{$table_entity_to_grp}` where idcontacts = ? LIMIT 1";
                 $this->query($qry_grp_rel, array($id_entity));
             } else {
                 $qry_grp_rel = "select * from `{$table_entity_to_grp}` where idcontacts = ?";
                 $this->query($qry_grp_rel, array($id_entity));
                 if ($this->getNumRows() > 0) {
                     $this->next();
                     $id_grp_rel = $this->idcnt_to_grp_rel;
                     $q_upd = "\n\t\t\t\t\t\tupdate `{$table_entity_to_grp}` set \n\t\t\t\t\t\t`idgroup` = ?\n\t\t\t\t\t\twhere `idcnt_to_grp_rel` = ? LIMIT 1";
                     $this->query($q_upd, array($group_id, $id_grp_rel));
                 } else {
                     $this->insert($table_entity_to_grp, array("idcontacts" => $id_entity, "idgroup" => $group_id));
                 }
             }
             // check if the avatar is uploaded and if yes update the files and attachment object
             if (is_array($avatar_array) && count($avatar_array) > 0 && $id_entity > 0) {
                 foreach ($avatar_array as $avatar) {
                     if (is_array($avatar) && array_key_exists('name', $avatar)) {
                         $do_files_and_attachment = new CRMFilesAndAttachments();
                         $do_files_and_attachment->addNew();
                         $do_files_and_attachment->file_name = $avatar["name"];
                         $do_files_and_attachment->file_mime = $avatar["mime"];
                         $do_files_and_attachment->file_size = $avatar["file_size"];
                         $do_files_and_attachment->file_extension = $avatar["extension"];
                         $do_files_and_attachment->idmodule = 4;
                         $do_files_and_attachment->id_referrer = $id_entity;
                         $do_files_and_attachment->iduser = $_SESSION["do_user"]->iduser;
                         $do_files_and_attachment->date_modified = date("Y-m-d H:i:s");
                         $do_files_and_attachment->add();
                         $do_files_and_attachment->free();
                     }
                 }
             }
             // Record the history
             $do_data_history = new DataHistory();
             $do_data_history->add_history($id_entity, (int) $evctl->idmodule, 'edit');
             $do_data_history->add_history_value_changes($id_entity, (int) $evctl->idmodule, $obj, $evctl);
             //record the feed
             $feed_other_assigne = array();
             if ($assigned_to_as_group === true) {
                 $feed_other_assigne = array("related" => "group", "data" => array("key" => "newgroup", "val" => $group_id));
             }
             $do_feed_queue = new LiveFeedQueue();
             $do_feed_queue->add_feed_queue($id_entity, (int) $evctl->idmodule, $evctl->firstname . ' ' . $evctl->lastname, 'edit', $feed_other_assigne);
             // process after update plugin
             $do_process_plugins->process_action_plugins((int) $evctl->idmodule, $evctl, 4, $id_entity, $obj);
             $_SESSION["do_crm_messages"]->set_message('success', _('Data updated successfully !'));
             $next_page = NavigationControl::getNavigationLink($evctl->module, "detail");
             $dis = new Display($next_page);
             $dis->addParam("sqrecord", $id_entity);
             $evctl->setDisplayNext($dis);
         }
     } else {
         $_SESSION["do_crm_messages"]->set_message('error', _('You do not have permission to edit the record ! '));
         $next_page = NavigationControl::getNavigationLink($evctl->module, "list");
         $dis = new Display($next_page);
         $evctl->setDisplayNext($dis);
     }
 }
Esempio n. 2
0
 /**
  * Function to remove the file from the server
  * @param string $name
  */
 public static function remove_thumb($name)
 {
     if ($name != '') {
         $avatar_path = $GLOBALS['AVATAR_PATH'];
         $do_files_and_attachment = new CRMFilesAndAttachments();
         $do_files_and_attachment->get_file_details_by_name($name);
         $file_extension = '';
         if ($do_files_and_attachment->getNumRows() > 0) {
             $do_files_and_attachment->next();
             $file_extension = $do_files_and_attachment->file_extension;
             $do_files_and_attachment->delete_record($do_files_and_attachment->idfile_uploads);
             $thumb_large_name = 'thl_' . $name . '.' . $file_extension;
             $thumb_medium_name = 'thm_' . $name . '.' . $file_extension;
             $thumb_small_name = 'ths_' . $name . '.' . $file_extension;
             if (is_file($avatar_path . '/' . $thumb_large_name)) {
                 unlink($avatar_path . '/' . $thumb_large_name);
             }
             if (is_file($avatar_path . '/' . $thumb_medium_name)) {
                 unlink($avatar_path . '/' . $thumb_medium_name);
             }
             if (is_file($avatar_path . '/' . $thumb_small_name)) {
                 unlink($avatar_path . '/' . $thumb_small_name);
             }
         }
     }
 }
Esempio n. 3
0
 /**
  * event function to change the user profile update
  * @param object $evctl
  * @return string
  */
 public function eventUploadUserAvatar(EventControler $evctl)
 {
     if ($_FILES["user_avatar"]["name"] == '') {
         echo '0';
     } else {
         if ($_FILES['user_avatar']['tmp_name'] != '') {
             $file_size = $_FILES['user_avatar']['size'];
             $hidden_file_name = 'upd_user_avatar';
             $current_file_name_in_db = $evctl->{$hidden_file_name};
             if ($current_file_name_in_db != '') {
                 FieldType12::remove_thumb($current_file_name_in_db);
             }
             $value = FieldType12::upload_avatar($_FILES['user_avatar']['tmp_name'], $_FILES['user_avatar']['name']);
             if (is_array($value) && array_key_exists('name', $value)) {
                 $qry = "\n\t\t\t\t\tupdate `" . $this->getTable() . "`\n\t\t\t\t\tset `user_avatar` = ?\n\t\t\t\t\twhere `iduser` = ?\n\t\t\t\t\t";
                 $this->getDbConnection()->executeQuery($qry, array($value['name'], $_SESSION["do_user"]->iduser));
                 $do_files_and_attachment = new CRMFilesAndAttachments();
                 $do_files_and_attachment->addNew();
                 $do_files_and_attachment->file_name = $value["name"];
                 $do_files_and_attachment->file_mime = $value["mime"];
                 $do_files_and_attachment->file_size = $file_size;
                 $do_files_and_attachment->file_extension = $value["extension"];
                 $do_files_and_attachment->idmodule = 7;
                 $do_files_and_attachment->id_referrer = $_SESSION["do_user"]->iduser;
                 $do_files_and_attachment->iduser = $_SESSION["do_user"]->iduser;
                 $do_files_and_attachment->date_modified = date("Y-m-d H:i:s");
                 $do_files_and_attachment->add();
                 $_SESSION["do_user"]->user_avatar = $value["name"];
                 echo FieldType12::get_file_name_with_path($value["name"], 's');
             } else {
                 echo '0';
             }
         } else {
             echo '0';
         }
     }
 }
Esempio n. 4
0
 /**
  * event function to delete the notes
  * @param object $evctl
  * first it will delete the note and then check if there are some document attached with it.
  * if documents are attached then delete from the database and then from physical location
  * @see class/core/CRMFilesAndAttachments.class.php
  * @see class/fields/fieldtypes/FieldType21.class.php
  */
 function eventAjaxDeleteNotes(\EventControler $evctl)
 {
     if ((int) $evctl->idnotes > 0) {
         $this->getId($evctl->idnotes);
         if ($_SESSION["do_cpaneluser"]->idcpanel_user === $this->idcpanel_user) {
             $qry = "\n\t\t\t\tdelete from `" . $this->getTable() . "`\n\t\t\t\twhere \n\t\t\t\t`idnotes` = ?\n\t\t\t\t";
             $this->query($qry, array((int) $evctl->idnotes));
             $do_files_and_attachment = new \CRMFilesAndAttachments();
             $do_files_and_attachment->get_uploaded_files(8, (int) $evctl->idnotes);
             if ($do_files_and_attachment->getNumRows() > 0) {
                 while ($do_files_and_attachment->next()) {
                     $file_name = $do_files_and_attachment->file_name;
                     $file_extension = $do_files_and_attachment->file_extension;
                     $do_files_and_attachment->delete_record($do_files_and_attachment->idfile_uploads);
                     \FieldType21::remove_file($file_name, $file_extension);
                 }
             }
             echo '1';
         } else {
             echo '0';
         }
     }
 }