/** * Deletes a user from the database. * @param Int $userid id of the user to be deleted. * return boolean true if user was successfully deleted, false otherwise. */ public function deleteUser($userid) { // safety checks if (empty($userid)) { return false; } // start transaction because we will perform several atomic operations. $this->dbConnector->startTransaction(); // first check if we need to remove the avatar. $data = $this->getDataForUser($userid); if (isset($data["avatar"])) { $ih = new \creamy\ImageHandler(); if (!$ih->removeUserAvatar($data["avatar"])) { $this->dbConnector->rollback(); return false; } } // delete the user notifications $this->dbConnector->where("target_user", $userid); if (!$this->dbConnector->delete(CRM_NOTIFICATIONS_TABLE_NAME)) { $this->dbConnector->rollback(); return false; } // delete the user events. $this->dbConnector->where("user_id", $userid); if (!$this->dbConnector->delete(CRM_EVENTS_TABLE_NAME)) { $this->dbConnector->rollback(); return false; } // deletes the user tasks $this->dbConnector->where("user_id", $userid); if (!$this->dbConnector->delete(CRM_TASKS_TABLE_NAME)) { $this->dbConnector->rollback(); return false; } // delete the user messages. // inbox $this->dbConnector->where("user_to", $userid); if (!$this->dbConnector->delete(CRM_MESSAGES_INBOX_TABLE_NAME)) { $this->dbConnector->rollback(); return false; } // outbox $this->dbConnector->where("user_from", $userid); if (!$this->dbConnector->delete(CRM_MESSAGES_OUTBOX_TABLE_NAME)) { $this->dbConnector->rollback(); return false; } // junk $this->dbConnector->where("user_to", $userid)->where("origin_folder", CRM_MESSAGES_INBOX_TABLE_NAME); if (!$this->dbConnector->delete(CRM_MESSAGES_JUNK_TABLE_NAME)) { $this->dbConnector->rollback(); return false; } $this->dbConnector->where("user_from", $userid)->where("origin_folder", CRM_MESSAGES_OUTBOX_TABLE_NAME); if (!$this->dbConnector->delete(CRM_MESSAGES_JUNK_TABLE_NAME)) { $this->dbConnector->rollback(); return false; } // last remove the user entry at the database $this->dbConnector->where("id", $userid); $result = $this->dbConnector->delete(CRM_USERS_TABLE_NAME); if ($result === true) { $this->dbConnector->commit(); return true; } else { $this->dbConnector->rollback(); return false; } }
$modifyid = $_POST["modifyid"]; $name = NULL; if (isset($_POST["name"])) { $name = $_POST["name"]; $name = stripslashes($name); $name = $db->escape_string($name); } $phone = NULL; if (isset($_POST["phone"])) { $phone = $_POST["phone"]; $phone = stripslashes($phone); $phone = $db->escape_string($phone); } $avatar = NULL; if (!empty($avatarOrigin)) { $imageHandler = new \creamy\ImageHandler(); $avatar = $imageHandler->generateAvatarFileAndReturnURL($avatarOrigin, $imageFileType); if (empty($avatar)) { $lh->translateText("unable_generate_user_image"); return; } } $userrole = CRM_DEFAULTS_USER_ROLE_GUEST; if (isset($_POST["role"])) { $userrole = $_POST["role"]; } // modify user data $result = $db->modifyUser($modifyid, $name, $phone, $userrole, $avatar); // analyze results. if ($result === true) { if ($modifyid == $user->getUserId()) {
$timezone = $_POST["timezone"]; $locale = $_POST["locale"]; $confirmationEmail = isset($_POST["confirmationEmail"]) ? true : false; $eventEmail = isset($_POST["eventEmail"]) ? true : false; $theme = $_POST["theme"]; $baseURL = $_POST["base_url"]; $minFreq = $_POST["jobScheduling"]; $customCompanyName = isset($_POST["company_name"]) ? $_POST["company_name"] : null; // generate settings array $data = array(CRM_SETTING_CONFIRMATION_EMAIL => $confirmationEmail, CRM_SETTING_THEME => $theme, CRM_SETTING_TIMEZONE => $timezone, CRM_SETTING_LOCALE => $locale, CRM_SETTING_COMPANY_NAME => $customCompanyName, CRM_SETTING_EVENTS_EMAIL => $eventEmail, CRM_SETTING_JOB_SCHEDULING_MIN_FREQ => $minFreq); if (!empty($baseURL)) { $data[CRM_SETTING_CRM_BASE_URL] = $baseURL; } // if we have a company custom logo, try to generate if first. if (isset($customLogoOrigin)) { $ih = new \creamy\ImageHandler(); $customLogoURL = $ih->generateCustomCompanyLogoAndReturnURL($customLogoOrigin, $imageFileType); if (isset($customLogoURL)) { $data[CRM_SETTING_COMPANY_LOGO] = $customLogoURL; } } // set settings $result = $db->setSettings($data); // return results. if ($result === true) { ob_clean(); print CRM_DEFAULT_SUCCESS_RESPONSE; } else { ob_clean(); $lh->translateText("error_accessing_database"); }