public function integratedBlock()
 {
     $xhtml = array();
     $user = Rp_User::getInstance();
     $user_id = $user->getPersonId();
     $companies = new Rp_Db_View_Companies();
     $departments = new Rp_Db_View_Departments();
     $employees = new Rp_Db_View_Employees();
     $appointments = new Rp_Db_View_Appointments();
     $integrated = new Rp_Db_View_IntegratedPersons();
     $integrate_note = "";
     $kol = 0;
     $xhtml[] = "<div class='caption_int'>Совмещенные должности</div>\r\n\r\n\t\t\t\t\t\t\t<table class='integrate_table'>\r\n\t\t\t\t\t\t\t\t<tr>\r\n\t\t\t\t\t\t\t\t\t<td width='30px' align='center'><b>№</b></td>\r\n\t\t\t\t\t\t\t\t\t<td align='center'><b>Компания</b></td>\r\n\t\t\t\t\t\t\t\t\t<td align='center'><b>Полный путь</b></td>\r\n\t\t\t\t\t\t\t\t\t<td align='center'><b>Должность</b></td>\r\n\t\t\t\t\t\t\t\t</tr>";
     //		if ($user_id < 90000000)
     switch ($user->persg) {
         case 2:
         case 3:
         case 7:
         case 8:
         case 'S':
             $person_id = $integrated->fetchPersonID($user_id);
             $refer_id = $integrated->fetchRefID($person_id[0]);
             $employee = $employees->findByPersonId($person_id[0])->current();
             $company = current($companies->fetchNames($employee->company_id));
             $department = current($departments->fetchNames($employee->department_id));
             $appointment = current($appointments->fetchNames($employee->appointment_id));
             $full_path = $employee->getPerson()->FullPath;
             $integrate_note = "<div class='integrate_note'>* основное место работы</div>";
             $xhtml[] = "<tr style='color: blue;'>\r\n\t\t\t\t\t\t\t\t\t<td align='center'>" . ++$kol . "*</td>\r\n\t\t\t\t\t\t\t\t\t<td><a href='#' style='color: blue;' onclick='forwardIntegratePerson(" . $person_id[0] . ")'>" . $company . "</a></td>\r\n\t\t\t\t\t\t\t\t\t<td><a href='#' style='color: blue;' onclick='forwardIntegratePerson(" . $person_id[0] . ")'>" . $full_path . "</a></td>\r\n\t\t\t\t\t\t\t\t\t<td><a href='#' style='color: blue;' onclick='forwardIntegratePerson(" . $person_id[0] . ")'>" . $appointment . "</a></td>\r\n\t\t\t\t\t\t\t</tr>";
             break;
         default:
             $refer_id = $integrated->fetchRefID($user_id);
             break;
     }
     foreach ($refer_id as $item) {
         if ($user_id == $item) {
             continue;
         } else {
             $employee = $employees->findByPersonId($item)->current();
             $company = current($companies->fetchNames($employee->company_id));
             $department = current($departments->fetchNames($employee->department_id));
             $appointment = current($appointments->fetchNames($employee->appointment_id));
             $full_path = $employee->getPerson()->FullPath;
             $xhtml[] = "<tr>\r\n\t\t\t\t\t\t\t\t<td align='center'>" . ++$kol . "</td>\r\n\t\t\t\t\t\t\t\t<td><a  style='color: black;' href='#' onclick='forwardIntegratePerson(" . $item . ")'>" . $company . "</a></td>\r\n\t\t\t\t\t\t\t\t<td><a  style='color: black;' href='#' onclick='forwardIntegratePerson(" . $item . ")'>" . $full_path . "</a></td>\r\n\t\t\t\t\t\t\t\t<td><a  style='color: black;' href='#' onclick='forwardIntegratePerson(" . $item . ")'>" . $appointment . "</a></td>\r\n\t\t\t\t\t\t\t</tr>";
         }
     }
     $xhtml[] = "</table>" . $integrate_note . "<br><br>";
     return implode($xhtml);
 }
    public function achievsHeader(Rp_Db_View_Row_Employee $emp)
    {
        $persons = new Rp_Db_View_Persons();
        $companies = new Rp_Db_View_Companies();
        $departments = new Rp_Db_View_Departments();
        $appointments = new Rp_Db_View_Appointments();
        $category = $emp->isManager() ? 'Руководитель' : 'Сотрудник';
        $managersIds = $emp->getManagers()->getCol('person_id');
        $managers = implode('<br />', $persons->fetchFullnames($managersIds));
        $is_integrate = "";
        //		if ($emp->person_id >= 90000000)
        switch ($emp->persg) {
            case 2:
            case 3:
            case 7:
            case 8:
            case 'S':
                $is_integrate = "<span style='color: blue; font-size: 12px;'>(совместитель)</span>";
                break;
        }
        $is_testperiod = '';
        if ($emp->endtest_date >= date('Y-m-d')) {
            $is_testperiod = '<span style="color: green; font-size: 12px;">&nbsp;(испытательный срок)</span>';
        }
        // если ID компании и ID отдела совпадают, то в поле отдел пишем знак '-', так как люди привязаны к юр. лицу напрямую
        $dep_name = "-";
        if ($emp->department_id != '-') {
            $dep_name = current($departments->fetchNames($emp->department_id));
        }
        return '
			<table class="header" cellspacing="5">
				<tbody>
					<tr>
						<td class="header-field-name">Сотрудник<div>Employee</div></td>
						<td class="header-field-value">
							<div>' . $emp->getPerson()->fullname . '</div>
							<input type="hidden" id="employee_fio" value="' . $emp->getPerson()->fullname . '" />
						</td>
						<td class="header-field-name">Категория<div>Category</div></td>
						<td class="header-field-value"><div>' . $category . '</div></td>
						<td class="header-field-name">Руководитель<div>Manager</div></td>
						<td class="header-field-value"><div>' . $managers . '</div></td>
						<td class="header-field-empty"></td>
					</tr>
					<tr>
						<td class="header-field-name">Компания<div>Company</div></td>
						<td class="header-field-value">
							<div>' . current($companies->fetchNames($emp->company_id)) . '</div></td>
						<td class="header-field-name">Отдел<div>Department</div></td>
						<td class="header-field-value">
							<div>' . $dep_name . '</div></td>
						<td class="header-field-name">Должность<div>Position</div></td>
						<td class="header-field-value">
							<div>' . current($appointments->fetchNames($emp->appointment_id)) . $is_integrate . $is_testperiod . '</div></td>
					</tr>
				</tbody>
			</table>
		';
    }
 public function indexAction()
 {
     $request = $this->getRequest();
     $authtype = Rp_Auth_Adapter_DbTable::AUTH_TRANSPARENT;
     $username = basename($request->getServer('AUTH_USER', NULL));
     $password = '';
     if ($_POST or isset($_GET['force_auth'])) {
         $authtype = Rp_Auth_Adapter_DbTable::AUTH_FORM;
         $username = $request->getPost('username', NULL);
         $password = $request->getPost('password', NULL);
     }
     $message = '';
     if ($username) {
         try {
             $auth = Zend_Auth::getInstance();
             $adapter = new Rp_Auth_Adapter_DbTable($username, $password, $authtype);
             $result = $auth->authenticate($adapter);
             if ($result->isValid()) {
                 $row = $adapter->getResultRowObject('id');
                 Rp_User::setInstance($row->id);
                 $user = Rp_User::getInstance();
                 $appointments = new Rp_Db_View_Appointments();
                 $log = new Rp_Db_Table_Logon();
                 if (!isset($_SESSION['user_id'])) {
                     $logon = array();
                     $logon['session_id'] = session_id();
                     $logon['user_id'] = $user->getPerson()->id;
                     $logon['userfullname'] = $user->getPerson()->fullname;
                     $logon['userpost'] = current($appointments->fetchNames($user->getEmployee()->appointment_id));
                     $logon['date_logon'] = date("m.d.y H:i:s");
                     $logon['ip'] = $_SERVER['REMOTE_ADDR'];
                     $logon['version'] = $_SERVER['HTTP_USER_AGENT'];
                     $log->insert($logon);
                     $_SESSION['user_id'] = $user->getPerson()->id;
                 }
                 $this->_forward('index', 'index');
                 return;
             } elseif ($result->getCode() != Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND) {
                 $message = implode("\n", $result->getMessages());
             } elseif ($authtype == Rp_Auth_Adapter_DbTable::AUTH_FORM) {
                 $message = 'ѕользователь с указанным сочетанием логин/пароль не найден.';
             }
         } catch (Exception $e) {
             $message = $e->getMessage();
         }
     }
     $view = $this->initView();
     $view->title = Rp::getTitle('јвторизаци¤');
     $view->message = $message;
 }