public static function storeRecords($records, $user, $type = HOLIDAY_TYPE_COMPANY_HOLIDAY, $annual = 1, $description = "") { global $AppUI; foreach ($records as $record) { $startDate = $record['startDate']->getPrevDay()->format('%Y-%m-%d'); $endDate = $record['endDate']->getNextDay()->format('%Y-%m-%d'); $q = new w2p_Database_Query(); $q->addTable("holiday"); $q->addQuery("*"); $where = "( date(holiday_start_date) = '"; $where .= $endDate; $where .= "' OR date(holiday_end_date) = '"; $where .= $startDate; $where .= "' )"; $where .= " AND holiday_user="******" AND holiday_type=" . $type; $where .= " AND holiday_annual=" . $annual; $where .= " AND holiday_description=" . $q->quote($description); $q->addWhere($where); $q->addOrder('holiday_start_date'); $list = $q->loadList(); $obj = new CHoliday(); switch (sizeof($list)) { case 0: if (!$obj->bind($record)) { $AppUI->setMsg($obj->getError(), UI_MSG_ERROR); $AppUI->redirect(); } break; case 1: $item = $list[0]; $obj->load($item['holiday_id']); if (substr($item['holiday_start_date'], 0, 10) == $endDate) { $obj->holiday_start_date = $record['endDate']->getDate(); } else { $obj->holiday_end_date = $record['startDate']->getDate(); } break; case 2: $item1 = $list[0]; $item2 = $list[1]; if (substr($item1['holiday_end_date'], 0, 10) != $startDate || substr($item2['holiday_start_date'], 0, 10) != $endDate) { $AppUI->setMsg($AppUI->_('User holidays inconsistency'), UI_MSG_ERROR); $AppUI->redirect(); } $obj2 = new CHoliday(); $obj2->load($item2['holiday_id']); $result = $obj2->delete($AppUI); if (is_string($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); $AppUI->redirect(); } $obj->load($item1['holiday_id']); $obj->holiday_end_date = $item2['holiday_end_date']; break; default: $AppUI->setMsg($AppUI->_('User holidays inconsistency'), UI_MSG_ERROR); $AppUI->redirect(); } $result = $obj->store($AppUI); if (is_string($result)) { $AppUI->setMsg($result, UI_MSG_ERROR); $AppUI->redirect(); } } }
function w2PgetUsersHashList($stub = null, $where = null, $orderby = 'contact_first_name, contact_last_name') { global $AppUI; $q = new w2p_Database_Query(); $q->addTable('users'); $q->addQuery('DISTINCT(user_id), user_username, contact_last_name, contact_first_name, company_name, contact_company, dept_id, dept_name, CONCAT(contact_first_name,\' \',contact_last_name) contact_name, user_type'); $q->addJoin('contacts', 'con', 'con.contact_id = user_contact', 'inner'); if ($stub) { $q->addWhere('(UPPER(user_username) LIKE \'' . $stub . '%\' or UPPER(contact_first_name) LIKE \'' . $stub . '%\' OR UPPER(contact_last_name) LIKE \'' . $stub . '%\')'); } elseif ($where) { $where = $q->quote('%' . $where . '%'); $q->addWhere('(UPPER(user_username) LIKE ' . $where . ' OR UPPER(contact_first_name) LIKE ' . $where . ' OR UPPER(contact_last_name) LIKE ' . $where . ')'); } $q->addQuery('contact_email'); $q->addGroup('user_id'); $q->addOrder($orderby); // get CCompany() to filter by company $obj = new CCompany(); $companies = $obj->getAllowedSQL($AppUI->user_id, 'company_id'); $q->addJoin('companies', 'com', 'company_id = contact_company'); if ($companies) { $q->addWhere('(' . implode(' OR ', $companies) . ' OR contact_company=\'\' OR contact_company IS NULL OR contact_company = 0)'); } $dpt = new CDepartment(); $depts = $dpt->getAllowedSQL($AppUI->user_id, 'dept_id'); $q->addJoin('departments', 'dep', 'dept_id = contact_department'); if ($depts) { $q->addWhere('(' . implode(' OR ', $depts) . ' OR contact_department=0)'); } return $q->loadHashList('user_id'); }