function returnFileValidationError() { //Make sure we return a complete validation error to be displayed to the user. $validator_obj = new Validator(); $validator_stats = array('total_records' => 1, 'valid_records' => 0); $validator_obj->isTrue('file', FALSE, TTi18n::getText('Please upload file again')); $validator[0] = $validator_obj->getErrorsArray(); return $this->returnHandler(FALSE, 'IMPORT_FILE', TTi18n::getText('INVALID DATA'), $validator, $validator_stats); }
/** * Delete one or more users. * @param array $data user data * @return array */ function deleteUser($data) { if (is_numeric($data)) { $data = array($data); } if (DEMO_MODE == TRUE) { return $this->returnHandler(TRUE); } if (!is_array($data)) { return $this->returnHandler(FALSE); } if (!$this->getPermissionObject()->Check('user', 'enabled') or !($this->getPermissionObject()->Check('user', 'delete') or $this->getPermissionObject()->Check('user', 'delete_own') or $this->getPermissionObject()->Check('user', 'delete_child'))) { return $this->getPermissionObject()->PermissionDenied(); } //Get Permission Hierarchy Children first, as this can be used for viewing, or editing. $permission_children_ids = $this->getPermissionChildren(); Debug::Text('Received data for: ' . count($data) . ' Users', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); $total_records = count($data); $validator_stats = array('total_records' => $total_records, 'valid_records' => 0); if (is_array($data)) { $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records); foreach ($data as $key => $id) { $primary_validator = new Validator(); $lf = TTnew('UserListFactory'); $lf->StartTransaction(); if (is_numeric($id)) { if ($this->getPermissionObject()->Check('company', 'view') == TRUE) { $lf->getById($id); //Allow deleting employees in other companies. } else { $lf->getByIdAndCompanyId($id, $this->getCurrentCompanyObject()->getId()); } if ($lf->getRecordCount() == 1) { //Object exists, check edit permissions //Debug::Text('User ID: '. $user['id'] .' Created By: '. $lf->getCurrent()->getCreatedBy() .' Is Owner: '. (int)$this->getPermissionObject()->isOwner( $lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID() ) .' Is Child: '. (int)$this->getPermissionObject()->isChild( $lf->getCurrent()->getId(), $permission_children_ids ), __FILE__, __LINE__, __METHOD__, 10); if ($this->getPermissionObject()->Check('user', 'delete') or $this->getPermissionObject()->Check('user', 'delete_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE or $this->getPermissionObject()->Check('user', 'delete_child') and $this->getPermissionObject()->isChild($lf->getCurrent()->getId(), $permission_children_ids) === TRUE) { Debug::Text('Record Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10); $lf = $lf->getCurrent(); } else { $primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Delete permission denied')); } } else { //Object doesn't exist. $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist')); } } else { $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist')); } //Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10); $is_valid = $primary_validator->isValid(); if ($is_valid == TRUE) { //Check to see if all permission checks passed before trying to save data. Debug::Text('Attempting to delete record...', __FILE__, __LINE__, __METHOD__, 10); $lf->setDeleted(TRUE); $is_valid = $lf->isValid(); if ($is_valid == TRUE) { Debug::Text('Record Deleted...', __FILE__, __LINE__, __METHOD__, 10); $save_result[$key] = $lf->Save(); $validator_stats['valid_records']++; } } if ($is_valid == FALSE) { Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10); $lf->FailTransaction(); //Just rollback this single record, continue on to the rest. if ($primary_validator->isValid() == FALSE) { $validator[$key] = $primary_validator->getErrorsArray(); } else { $validator[$key] = $lf->Validator->getErrorsArray(); } } $lf->CommitTransaction(); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } $this->getProgressBarObject()->stop($this->getAMFMessageID()); if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) { if ($validator_stats['total_records'] == 1) { return $this->returnHandler($save_result[$key]); //Single valid record } else { return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats); //Multiple valid records } } else { return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats); } } return $this->returnHandler(FALSE); }
/** * Delete one or more UserPreferences. * @param array $data UserPreference data * @return array */ function deleteUserPreference($data) { if (is_numeric($data)) { $data = array($data); } if (!is_array($data)) { return $this->returnHandler(FALSE); } if (!$this->getPermissionObject()->Check('user_preference', 'enabled') or !($this->getPermissionObject()->Check('user_preference', 'delete') or $this->getPermissionObject()->Check('user_preference', 'delete_own') or $this->getPermissionObject()->Check('user_preference', 'delete_child'))) { return $this->getPermissionObject()->PermissionDenied(); } Debug::Text('Received data for: ' . count($data) . ' UserPreferences', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); $total_records = count($data); $validator_stats = array('total_records' => $total_records, 'valid_records' => 0); if (is_array($data)) { $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records); foreach ($data as $key => $id) { $primary_validator = new Validator(); $lf = TTnew('UserPreferenceListFactory'); $lf->StartTransaction(); if (is_numeric($id)) { //Modifying existing object. //Get UserPreference object, so we can only modify just changed data for specific records if needed. $lf->getByIdAndCompanyId($id, $this->getCurrentCompanyObject()->getId()); if ($lf->getRecordCount() == 1) { //Object exists, check edit permissions if ($this->getPermissionObject()->Check('user_preference', 'delete') or $this->getPermissionObject()->Check('user_preference', 'delete_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE) { Debug::Text('Record Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10); $lf = $lf->getCurrent(); } else { $primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Delete permission denied')); } } else { //Object doesn't exist. $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist')); } } else { $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist')); } //Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10); $is_valid = $primary_validator->isValid(); if ($is_valid == TRUE) { //Check to see if all permission checks passed before trying to save data. Debug::Text('Attempting to delete record...', __FILE__, __LINE__, __METHOD__, 10); $lf->setDeleted(TRUE); $is_valid = $lf->isValid(); if ($is_valid == TRUE) { Debug::Text('Record Deleted...', __FILE__, __LINE__, __METHOD__, 10); $save_result[$key] = $lf->Save(); $validator_stats['valid_records']++; } } if ($is_valid == FALSE) { Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10); $lf->FailTransaction(); //Just rollback this single record, continue on to the rest. if ($primary_validator->isValid() == FALSE) { $validator[$key] = $primary_validator->getErrorsArray(); } else { $validator[$key] = $lf->Validator->getErrorsArray(); } } $lf->CommitTransaction(); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } $this->getProgressBarObject()->stop($this->getAMFMessageID()); if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) { if ($validator_stats['total_records'] == 1) { return $this->returnHandler($save_result[$key]); //Single valid record } else { return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats); //Multiple valid records } } else { return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats); } } return $this->returnHandler(FALSE); }
/** * Delete one or more users. * @param array $data user data * @return array */ function deleteUserGenericData($data) { Debug::Arr($data, 'DataA: ', __FILE__, __LINE__, __METHOD__, 10); if (is_numeric($data)) { $data = array($data); } if (!is_array($data)) { return $this->returnHandler(FALSE); } Debug::Text('Received data for: ' . count($data) . ' Users', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); $total_records = count($data); $validator_stats = array('total_records' => $total_records, 'valid_records' => 0); if (is_array($data)) { foreach ($data as $key => $id) { $primary_validator = new Validator(); $lf = TTnew('UserGenericDataListFactory'); $lf->StartTransaction(); if (is_numeric($id)) { //Modifying existing object. //Get user object, so we can only modify just changed data for specific records if needed. $lf->getByUserIdAndId($this->getCurrentUserObject()->getId(), $id); if ($lf->getRecordCount() == 1) { //Object exists Debug::Text('User Generic Data Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10); $lf = $lf->getCurrent(); } else { //Object doesn't exist. $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, generic data does not exist')); } } else { $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, generic data does not exist')); } //Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10); $is_valid = $primary_validator->isValid(); if ($is_valid == TRUE) { //Check to see if all permission checks passed before trying to save data. Debug::Text('Attempting to delete user generic data...', __FILE__, __LINE__, __METHOD__, 10); $lf->setDeleted(TRUE); $is_valid = $lf->isValid(); if ($is_valid == TRUE) { Debug::Text('User Deleted...', __FILE__, __LINE__, __METHOD__, 10); $save_result[$key] = $lf->Save(); $validator_stats['valid_records']++; } } if ($is_valid == FALSE) { Debug::Text('User Generic Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10); $lf->FailTransaction(); //Just rollback this single record, continue on to the rest. if ($primary_validator->isValid() == FALSE) { $validator[$key] = $primary_validator->getErrorsArray(); } else { $validator[$key] = $lf->Validator->getErrorsArray(); } } $lf->CommitTransaction(); } if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) { if ($validator_stats['total_records'] == 1) { return $this->returnHandler($save_result[$key]); //Single valid record } else { return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats); //Multiple valid records } } else { return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats); } } return $this->returnHandler(FALSE); }
function Login($user_name, $password = NULL, $type = 'USER_NAME') { global $config_vars; $authentication = new Authentication(); Debug::text('User Name: ' . $user_name . ' Password Length: ' . strlen($password) . ' Type: ' . $type, __FILE__, __LINE__, __METHOD__, 10); //FIXME: When using Flex, I think it sets the cookie itself, so we need to pass this information on to it before it will actually work. //However this should work fine for JSON/SOAP. //FIXME: Store the type in the authentication table so we know how the user logged in. Then we can disable certain functionality if using the phone_id. if (isset($config_vars['other']['web_session_expire']) and $config_vars['other']['web_session_expire'] != '') { $authentication->setEnableExpireSession((int) $config_vars['other']['web_session_expire']); } if ($authentication->Login($user_name, $password, $type) === TRUE) { $retval = $authentication->getSessionId(); Debug::text('Success, Session ID: ' . $retval, __FILE__, __LINE__, __METHOD__, 10); return $retval; } else { $validator_obj = new Validator(); $validator_stats = array('total_records' => 1, 'valid_records' => 0); $error_column = 'user_name'; $error_message = TTi18n::gettext('User Name or Password is incorrect'); //Get company status from user_name, so we can display messages for ONHOLD/Cancelled accounts. $clf = TTnew('CompanyListFactory'); $clf->getByUserName($user_name); if ($clf->getRecordCount() > 0) { $c_obj = $clf->getCurrent(); if ($c_obj->getStatus() == 20) { $error_message = TTi18n::gettext('Sorry, your company\'s account has been placed ON HOLD, please contact customer support immediately'); } elseif ($c_obj->getStatus() == 23) { $error_message = TTi18n::gettext('Sorry, your trial period has expired, please contact our sales department to reactivate your account'); } elseif ($c_obj->getStatus() == 28) { if ($c_obj->getMigrateURL() != '') { $error_message = TTi18n::gettext('To better serve our customers your account has been migrated, please update your bookmarks to use the following URL from now on: ') . 'http://' . $c_obj->getMigrateURL(); } else { $error_message = TTi18n::gettext('To better serve our customers your account has been migrated, please contact customer support immediately.'); } } elseif ($c_obj->getStatus() == 30) { $error_message = TTi18n::gettext('Sorry, your company\'s account has been CANCELLED, please contact customer support if you believe this is an error'); } elseif ($c_obj->getPasswordPolicyType() == 1 and $c_obj->getProductEdition() > 10) { //Password policy is enabled, confirm users password has not exceeded maximum age. $ulf = TTnew('UserListFactory'); $ulf->getByUserName($user_name); if ($ulf->getRecordCount() > 0) { foreach ($ulf as $u_obj) { //Make sure we confirm that the password is in fact correct, but just expired. if ($u_obj->checkPassword($password, FALSE) == TRUE and $u_obj->checkPasswordAge() == FALSE) { $error_message = TTi18n::gettext('Sorry, your password has exceeded its maximum age specified by your company\'s password policy and must be changed immediately'); $error_column = 'password'; } } } unset($ulf, $u_obj); } } $validator_obj->isTrue($error_column, FALSE, $error_message); $validator[0] = $validator_obj->getErrorsArray(); return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats); } return $this->returnHandler(FALSE); }
/** * Set log data for one or more loges. * @param array $data log data * @return array */ function setLog($data, $validate_only = FALSE) { $validate_only = (bool) $validate_only; if (!is_array($data)) { return $this->returnHandler(FALSE); } if ($validate_only == TRUE) { Debug::Text('Validating Only!', __FILE__, __LINE__, __METHOD__, 10); } extract($this->convertToMultipleRecords($data)); Debug::Text('Received data for: ' . $total_records . ' Logs', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); $validator_stats = array('total_records' => $total_records, 'valid_records' => 0); if (is_array($data)) { $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records); foreach ($data as $key => $row) { $primary_validator = new Validator(); $lf = TTnew('LogListFactory'); $lf->StartTransaction(); //Can add log entries only. unset($row['id']); Debug::Arr($row, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); Debug::Text('Setting object data...', __FILE__, __LINE__, __METHOD__, 10); $lf->setObjectFromArray($row); //Force Company ID to current company. $lf->setUser($this->getCurrentUserObject()->getId()); $is_valid = $lf->isValid(); if ($is_valid == TRUE) { Debug::Text('Saving data...', __FILE__, __LINE__, __METHOD__, 10); if ($validate_only == TRUE) { $save_result[$key] = TRUE; } else { $save_result[$key] = $lf->Save(); } $validator_stats['valid_records']++; } if ($is_valid == FALSE) { Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10); $lf->FailTransaction(); //Just rollback this single record, continue on to the rest. if ($primary_validator->isValid() == FALSE) { $validator[$key] = $primary_validator->getErrorsArray(); } else { $validator[$key] = $lf->Validator->getErrorsArray(); } } $lf->CommitTransaction(); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } $this->getProgressBarObject()->stop($this->getAMFMessageID()); if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) { if ($validator_stats['total_records'] == 1) { return $this->returnHandler($save_result[$key]); //Single valid record } else { return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats); //Multiple valid records } } else { return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats); } } return $this->returnHandler(FALSE); }
/** * Delete one or more recurring_schedule_controls. * @param array $data recurring_schedule_control data * @return array */ function deleteRecurringScheduleControl($data) { if (is_numeric($data)) { $data = array($data); } if (!is_array($data)) { return $this->returnHandler(FALSE); } if (!$this->getPermissionObject()->Check('recurring_schedule', 'enabled') or !($this->getPermissionObject()->Check('recurring_schedule', 'delete') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_own') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_child'))) { return $this->getPermissionObject()->PermissionDenied(); } //Get Permission Hierarchy Children first, as this can be used for viewing, or editing. $permission_children_ids = $this->getPermissionChildren(); Debug::Text('Received data for: ' . count($data) . ' RecurringScheduleControls', __FILE__, __LINE__, __METHOD__, 10); Debug::Arr($data, 'Data: ', __FILE__, __LINE__, __METHOD__, 10); $total_records = count($data); $validator_stats = array('total_records' => $total_records, 'valid_records' => 0); if (is_array($data)) { $this->getProgressBarObject()->start($this->getAMFMessageID(), $total_records); foreach ($data as $key => $tmp_id) { $primary_validator = new Validator(); $lf = TTnew('RecurringScheduleControlListFactory'); $lf->StartTransaction(); //Need to support deleting the entire recurring schedule, or just one user from it. if (is_array($tmp_id)) { $id = $key; $user_id = $tmp_id; Debug::Arr($tmp_id, 'ID is an array, with User ID specified as well, deleting just this one user: ID: ' . $id . ' User IDs: ', __FILE__, __LINE__, __METHOD__, 10); } else { $id = $tmp_id; $user_id = FALSE; } if (is_numeric($id)) { //Modifying existing object. //Get recurring_schedule_control object, so we can only modify just changed data for specific records if needed. $lf->getByIdAndCompanyId($id, $this->getCurrentCompanyObject()->getId()); if ($lf->getRecordCount() == 1) { //Object exists, check edit permissions if ($this->getPermissionObject()->Check('recurring_schedule', 'delete') or $this->getPermissionObject()->Check('recurring_schedule', 'delete_own') and $this->getPermissionObject()->isOwner($lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID()) === TRUE or $this->getPermissionObject()->Check('recurring_schedule', 'delete_child') and $this->getPermissionObject()->isChild($user_id, $permission_children_ids) === TRUE) { //if ( $this->getPermissionObject()->Check('recurring_schedule','delete') // OR ( $this->getPermissionObject()->Check('recurring_schedule','delete_own') AND $this->getPermissionObject()->isOwner( $lf->getCurrent()->getCreatedBy(), $lf->getCurrent()->getID() ) === TRUE ) ) { Debug::Text('Record Exists, deleting record: ', $id, __FILE__, __LINE__, __METHOD__, 10); $lf = $lf->getCurrent(); } else { $primary_validator->isTrue('permission', FALSE, TTi18n::gettext('Delete permission denied')); } } else { //Object doesn't exist. $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist')); } } else { $primary_validator->isTrue('id', FALSE, TTi18n::gettext('Delete permission denied, record does not exist')); } //Debug::Arr($lf, 'AData: ', __FILE__, __LINE__, __METHOD__, 10); $is_valid = $primary_validator->isValid(); if ($is_valid == TRUE) { //Check to see if all permission checks passed before trying to save data. Debug::Text('Attempting to delete record...', __FILE__, __LINE__, __METHOD__, 10); if ($user_id > 0) { //Remove this user_id from the user array. $new_user_ids = array_diff((array) $lf->getUser(), (array) $user_id); Debug::Arr($new_user_ids, 'Removing individual users from schedule, remaining users are: ', __FILE__, __LINE__, __METHOD__, 10); if (count($new_user_ids) > 0) { $lf->setUser($new_user_ids); } else { //No users left, delete the entire recurring schedule. Debug::Text('No users left in schedule, removing entire schedule...', __FILE__, __LINE__, __METHOD__, 10); $lf->setDeleted(TRUE); } unset($new_user_ids); } else { $lf->setDeleted(TRUE); } $is_valid = $lf->isValid(); if ($is_valid == TRUE) { Debug::Text('Record Deleted...', __FILE__, __LINE__, __METHOD__, 10); $save_result[$key] = $lf->Save(); $validator_stats['valid_records']++; } } if ($is_valid == FALSE) { Debug::Text('Data is Invalid...', __FILE__, __LINE__, __METHOD__, 10); $lf->FailTransaction(); //Just rollback this single record, continue on to the rest. if ($primary_validator->isValid() == FALSE) { $validator[$key] = $primary_validator->getErrorsArray(); } else { $validator[$key] = $lf->Validator->getErrorsArray(); } } $lf->CommitTransaction(); $this->getProgressBarObject()->set($this->getAMFMessageID(), $key); } $this->getProgressBarObject()->stop($this->getAMFMessageID()); if ($validator_stats['valid_records'] > 0 and $validator_stats['total_records'] == $validator_stats['valid_records']) { if ($validator_stats['total_records'] == 1) { return $this->returnHandler($save_result[$key]); //Single valid record } else { return $this->returnHandler(TRUE, 'SUCCESS', TTi18n::getText('MULTIPLE RECORDS SAVED'), $save_result, $validator_stats); //Multiple valid records } } else { return $this->returnHandler(FALSE, 'VALIDATION', TTi18n::getText('INVALID DATA'), $validator, $validator_stats); } } return $this->returnHandler(FALSE); }