function getByCompanyId($company_id, $where = NULL, $order = NULL)
    {
        if ($company_id == '') {
            return FALSE;
        }
        $udf = new UserDefaultFactory();
        $ph = array('company_id' => $company_id);
        $query = '
					select 	a.*
					from	' . $this->getTable() . ' as a
					LEFT JOIN ' . $udf->getTable() . ' as udf ON a.user_default_id = udf.id
					where	udf.company_id = ?
						AND ( udf.deleted = 0 )';
        $query .= $this->getWhereSQL($where);
        $query .= $this->getSortSQL($order);
        $this->ExecuteSQL($query, $ph);
        return $this;
    }
 function postSave()
 {
     if ($this->getDeleted() == TRUE) {
         Debug::Text('UnAssign title from employees: ' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10);
         //Unassign hours from this job.
         $uf = new UserFactory();
         $udf = new UserDefaultFactory();
         $query = 'update ' . $uf->getTable() . ' set title_id = 0 where company_id = ' . $this->getCompany() . ' AND title_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $udf->getTable() . ' set title_id = 0 where company_id = ' . $this->getCompany() . ' AND title_id = ' . $this->getId();
         $this->db->Execute($query);
     }
 }
 function postSave()
 {
     if ($this->getDeleted() == TRUE) {
         Debug::Text('UnAssign Policy Group from User Defaults...' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10);
         $udf = new UserDefaultFactory();
         $query = 'update ' . $udf->getTable() . ' set policy_group_id = 0 where company_id = ' . $this->getCompany() . ' AND policy_group_id = ' . $this->getId();
         $this->db->Execute($query);
     }
     return TRUE;
 }
 function postSave()
 {
     $this->removeCache($this->getId());
     if ($this->getDeleted() == TRUE) {
         Debug::Text('UnAssign Hours from Branch: ' . $this->getId(), __FILE__, __LINE__, __METHOD__, 10);
         //Unassign hours from this branch.
         $pcf = new PunchControlFactory();
         $udtf = new UserDateTotalFactory();
         $uf = new UserFactory();
         $sf = new StationFactory();
         $sf_b = new ScheduleFactory();
         $udf = new UserDefaultFactory();
         $rstf = new RecurringScheduleTemplateFactory();
         $query = 'update ' . $pcf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $udtf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $sf_b->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $uf->getTable() . ' set default_branch_id = 0 where company_id = ' . $this->getCompany() . ' AND default_branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $udf->getTable() . ' set default_branch_id = 0 where company_id = ' . $this->getCompany() . ' AND default_branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $sf->getTable() . ' set branch_id = 0 where company_id = ' . $this->getCompany() . ' AND branch_id = ' . $this->getId();
         $this->db->Execute($query);
         $query = 'update ' . $rstf->getTable() . ' set branch_id = 0 where branch_id = ' . $this->getId();
         $this->db->Execute($query);
     }
     return TRUE;
 }
}
$smarty->assign('title', TTi18n::gettext($title = 'New Hire Defaults'));
// See index.php
/*
 * Get FORM variables
 */
extract(FormVariables::GetVariables(array('action', 'id', 'user_data', 'data_saved')));
if (isset($user_data)) {
    if (isset($user_data['hire_date']) and $user_data['hire_date'] != '') {
        $user_data['hire_date'] = TTDate::parseDateTime($user_data['hire_date']);
    }
}
$uf = new UserFactory();
$upf = new UserPreferenceFactory();
$udlf = new UserDefaultListFactory();
$udf = new UserDefaultFactory();
$action = Misc::findSubmitButton();
switch ($action) {
    case 'submit':
        Debug::Text('Submit!', __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        if (isset($user_data['id']) and $user_data['id'] != '') {
            $udf->setId($user_data['id']);
        }
        $udf->setCompany($current_company->getId());
        $udf->setTitle($user_data['title_id']);
        $udf->setCity($user_data['city']);
        $udf->setCountry($user_data['country']);
        $udf->setProvince($user_data['province']);
        $udf->setWorkPhone($user_data['work_phone']);
        $udf->setWorkPhoneExt($user_data['work_phone_ext']);