/**
  * Переход проекта в другой возможный стастус
  * 
  * @param string $new_status
  * @return boolean
  */
 public function changeStatus($new_status)
 {
     $list = $this->is_emp ? $this->STATUS_EMP_LIST : $this->STATUS_FRL_LIST;
     $next = $this->STATUS_NEXT;
     //Существует ли новый статус
     if (!isset($list[$new_status])) {
         return FALSE;
     }
     $status = $list[$new_status];
     //Есть ли принадлежность для него?
     if (!isset($this->current_table[$status])) {
         return FALSE;
     }
     $prop = $this->current_table[$status][1];
     $current_status = @$this->{$prop}['status'];
     //Есть ли текущий статус и возможен ли переход в новый
     if (!isset($next[$current_status]) || !in_array($list[$new_status], $next[$current_status])) {
         return FALSE;
     }
     $data = array('status' => $status);
     $time = time();
     //Действия перед сменой статуса
     switch ($status) {
         case self::STATUS_DECLINE:
         case self::STATUS_CANCEL:
             //Нельзя отказаться если уже согласился
             if ($this->project['status'] == self::STATUS_ACCEPT) {
                 return FALSE;
             }
             //Убираем из исполнителей
             $obj_project = new projects();
             $err = $obj_project->ClearExecutor($this->project['id'], $this->project['user_id']);
             if (!empty($err)) {
                 return FALSE;
             }
             $obj_offer = new projects_offers();
             if ($this->project['kind'] == 9) {
                 //У персонального проекта переводим в отказ
                 if ($status == self::STATUS_CANCEL) {
                     $obj_offer->SetRefused($this->offer['id'], $this->project['id'], $this->project['exec_id']);
                 } else {
                     $this->db()->update(self::TABLE_OFFERS, array('status' => -1), 'id = ?i', $this->offer['id']);
                 }
             } else {
                 //Переводим в кандидаты
                 $obj_offer->SetSelected($this->offer['id'], $this->project['id'], $this->project['exec_id'], true);
             }
             $this->project['exec_id'] = NULL;
             //Если это персональный проект
             //то закрываем его после отказа
             if ($this->project['kind'] == 9) {
                 $this->project['close_date'] = date('Y-m-d H:i:s', $time);
                 $this->project['closed'] = TRUE;
                 $this->db()->update(self::TABLE_PROJECTS, array('close_date' => $this->project['close_date'], 'closed' => $this->project['closed']), 'id = ?i', $this->project['id']);
             }
             break;
         case self::STATUS_ACCEPT:
             $now = date("Y-m-d H:i:s");
             $this->db()->update(self::TABLE_OFFERS, array('status' => 0), 'id = ?i', $this->offer['id']);
             $this->db()->update(self::TABLE_PROJECTS, array('accept_date' => $now), 'id = ?i', $this->project['id']);
             $this->offer['status'] = 0;
             //@todo: как снять проект с публикации???
             //будем учитывать этатус = 0 в выборках
             break;
         case self::STATUS_EMPCLOSE:
         case self::STATUS_FRLCLOSE:
             $data['close_date'] = date('Y-m-d H:i:s', $time);
             $data['closed'] = TRUE;
             $this->project['close_date'] = $data['close_date'];
             $this->project['closed'] = $data['closed'];
             break;
     }
     $table = $this->current_table[$status][0];
     $id = @$this->{$prop}['id'];
     $is_ok = $this->db()->update($table, $data, 'id = ?i', $id);
     if ($is_ok) {
         $this->{$prop}['status'] = $status;
         //Высылаем уведомления о смене статуса
         $mes = new projects_smail();
         //Действия после успешной смены статуса
         switch ($status) {
             case self::STATUS_ACCEPT:
                 $mes->onStartWorking($this->project, $this->offer);
                 break;
             case self::STATUS_CANCEL:
                 $mes->onRefuseFrl($this->project, $this->offer);
                 break;
             case self::STATUS_DECLINE:
                 $mes->onRefuseEmp($this->project, $this->offer);
                 break;
             case self::STATUS_EMPCLOSE:
             case self::STATUS_FRLCLOSE:
                 //Нет смысла тут пытаться уведомлять не имея еще отзыва!
                 //$mes->onFinish($this->project, $this->is_emp);
                 break;
         }
     }
     return $is_ok;
 }
Beispiel #2
0
                $user = new users();
                $prj_offer = new projects_offers();
                $po_reason = intval($_GET['refuse']);
                $emp_id = get_uid(false);
                $emp_name = $user->GetName($emp_id, $error);
                //Не позволяем производить действия с заблокированным проектом
                if (projects::CheckBlocked(intval($prj_id))) {
                    $objResponse->script("document.location.href='/projects/index.php?pid=" . intval($prj_id) . "'");
                } else {
                    $error = '';
                    $project = $prj->GetPrjCust($prj_id);
                    if ($project['exec_id'] == $user_id) {
                        $error = $prj->ClearExecutor($prj_id, $emp_id);
                    }
                    if (!$error) {
                        $prj_offer->SetRefused($po_id, $prj_id, $user_id, $po_reason, true);
                        header('Location: /projects/index.php?pid=' . intval($prj_id));
                        exit;
                    }
                }
            } else {
                $user = new users();
                $user_id = intval($user_id);
                $user->GetUserByUID($user_id);
            }
            $content = 'emp_refuse.php';
            include '../template2.php';
            exit;
        }
        break;
}
function RefuseProjectOffer($po_id, $prj_id, $user_id, $type, $po_reason = 0)
{
    global $session;
    session_start();
    $user = new users();
    $prj = new projects();
    $prj_offer = new projects_offers();
    $po_id = intval($po_id);
    $prj_id = intval($prj_id);
    $po_reason = intval($po_reason);
    $user_id = intval($user_id);
    $user_name = $user->GetName($user_id, $error);
    $emp_id = get_uid(false);
    $emp_name = $user->GetName($emp_id, $error);
    $pod = new projects_offers_dialogue();
    $pod->markReadEmp(array($po_id), $emp_id);
    $objResponse = new xajaxResponse();
    //Не позволяем производить действия с заблокированным проектом
    if (projects::CheckBlocked(intval($prj_id))) {
        $objResponse->script("document.location.href='/projects/index.php?pid=" . intval($prj_id) . "'");
    } else {
        $error = '';
        $project = $prj->GetPrjCust($prj_id);
        if ($project['exec_id'] == $user_id) {
            $error = $prj->ClearExecutor($prj_id, $emp_id);
        }
        if (!$error) {
            $error .= ($error ? ' ' : '') . $prj_offer->SetRefused($po_id, $prj_id, $user_id, $po_reason, true);
            $project = $prj->GetPrjCust($prj_id);
            require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/base.php';
            require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/api/api.php';
            require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/external/api/mobile.php';
            externalApi_Mobile::addPushMsg($user_id, 'prj_select_reject', array('from_user_id' => $project['user_id'], 'name' => $project['name'], 'project_id' => $project['id']));
            list($po_offers_count, $msg_offers_count) = $prj_offer->CountPrjOffers($prj_id, 'offers');
            $objResponse->assign('po_offers_count', 'innerHTML', $po_offers_count);
            if ($msg_offers_count > 0) {
                $objResponse->assign('op_count_offers_new_msgs', 'innerHTML', '<img src="/images/ico_envelop.gif" alt="" width="10" height="8" border="0"> ' . $msg_offers_count . ' ' . ending($msg_offers_count, 'новое сообщение', 'новых сообщения', 'новых сообщений'));
            } else {
                $objResponse->assign('op_count_offers_new_msgs', 'innerHTML', '');
                if ($type == 'o') {
                    $objResponse->remove('sort_box');
                }
            }
            list($po_executor_count, $msg_executor_count) = $prj_offer->CountPrjOffers($prj_id, 'executor');
            $objResponse->assign('po_executor_count', 'innerHTML', $po_executor_count);
            if ($msg_executor_count > 0) {
                $objResponse->assign('op_count_executor_new_msgs', 'innerHTML', '<img src="/images/ico_envelop.gif" alt="" width="10" height="8" border="0"> ' . $msg_executor_count . ' ' . ending($msg_executor_count, 'новое сообщение', 'новых сообщения', 'новых сообщений'));
            } else {
                $objResponse->assign('op_count_executor_new_msgs', 'innerHTML', '');
                if ($type == 'i') {
                    $objResponse->remove('sort_box');
                }
            }
            list($po_candidate_count, $msg_candidate_count) = $prj_offer->CountPrjOffers($prj_id, 'candidate');
            $objResponse->assign('po_candidate_count', 'innerHTML', $po_candidate_count);
            if ($msg_candidate_count > 0) {
                $objResponse->assign('op_count_candidate_new_msgs', 'innerHTML', '<img src="/images/ico_envelop.gif" alt="" width="10" height="8" border="0"> ' . $msg_candidate_count . ' ' . ending($msg_candidate_count, 'новое сообщение', 'новых сообщения', 'новых сообщений'));
            } else {
                $objResponse->assign('op_count_candidate_new_msgs', 'innerHTML', '');
                if ($type == 'c') {
                    $objResponse->remove('sort_box');
                }
            }
            list($po_refuse_count, $msg_refuse_count) = $prj_offer->CountPrjOffers($prj_id, 'refuse');
            $objResponse->assign('po_refuse_count', 'innerHTML', $po_refuse_count);
            if ($msg_refuse_count > 0) {
                $objResponse->assign('op_count_refuse_new_msgs', 'innerHTML', '<img src="/images/ico_envelop.gif" alt="" width="10" height="8" border="0"> ' . $msg_refuse_count . ' ' . ending($msg_refuse_count, 'новое сообщение', 'новых сообщения', 'новых сообщений'));
            } else {
                if ($type == 'r') {
                    $objResponse->remove('sort_box');
                }
                $objResponse->assign('op_count_refuse_new_msgs', 'innerHTML', '');
            }
            //$objResponse->assign("po_b_exec_" . $po_id, "innerHTML", '<a id="po_img_exec_' . $po_id . '" class="b-button-multi__link" onclick="xajax_SelectProjectExecutor(' . $po_id . ', ' . $prj_id . ', ' . $user_id . ', ' . "'" . $type . "'" . ', ' . 0 . ');" href="javascript:void(0)" title="Буду работать с этим человеком."><span class="b-button-multi__inner"><span class="b-button-multi__icon b-button-multi__icon_green"></span><span class="b-button-multi__txt">Исполнитель</span></span></a>');
            //$objResponse->assign("po_b_select_" . $po_id, "innerHTML", '<a id="po_img_select_' . $po_id . '" class="b-button-multi__link" onclick="xajax_SelectProjectOffer(' . $po_id . ', ' . $prj_id . ', ' . $user_id  . ', ' . "'" . $type . "'" . ');" href="javascript:void(0)" title="Прошел предварительный отбор. Может быть исполнителем"><span class="b-button-multi__inner"><span class="b-button-multi__icon b-button-multi__icon_blue"></span><span class="b-button-multi__txt">Кандидат</span></span></a>');
            //$objResponse->assign("po_b_refuse_" . $po_id, "innerHTML", '<a id="po_img_refuse_' . $po_id . '" class="b-button-multi__link"  href="javascript:void(0)" title="Этот человек мне не подходит.  Может быть в следующий раз."><span class="b-button-multi__inner"><span class="b-button-multi__icon b-button-multi__icon_red"></span><span class="b-button-multi__txt">Отказано</span></span></a>');
            $objResponse->script("removeNoteBar('{$user_name['login']}');");
            $objResponse->remove('po_' . $po_id);
            $objResponse->remove('po_u_' . $po_id);
            $objResponse->remove('po_bar_' . $po_id);
        }
        --$_SESSION['offers_on_page'];
        if ($_SESSION['offers_on_page'] == 0) {
            $objResponse->script("document.location.href='/projects/index.php?pid=" . intval($prj_id) . '&type=' . $type . "'");
        }
    }
    return $objResponse;
}
Beispiel #4
0
 /**
  * Выбор пользователя в предложении к проекту
  * 
  * @param  array $aParams массив входящих данных
  * @return array $aResult ответ
  */
 protected function x____projects_response_select($aParams = array())
 {
     $this->_validDevice($aParams);
     require_once ABS_PATH . '/classes/projects_offers.php';
     $nUid = get_uid(false);
     $oOffer = new projects_offers();
     $nId = intvalPgSql($aParams['id']);
     $aOffer = $oOffer->GetPrjOfferById($nId);
     if (is_array($aOffer) && $aOffer) {
         require_once ABS_PATH . '/classes/projects.php';
         $oPrj = new new_projects();
         $aProject = $oPrj->GetPrjCust($aOffer['project_id']);
         if (!empty($aProject) || $aProject['is_blocked'] == 'f') {
             // Не позволяем производить действия с заблокированным проектом
             if ($nUid == $aProject['user_id']) {
                 $nSelect = intvalPgSql($aParams['select']);
                 if ($nSelect > 0 && $nSelect < 4) {
                     $aOffer['emp_uid'] = $aProject['user_id'];
                     switch ($nSelect) {
                         case 1:
                             $error = false;
                             if ($aProject['exec_id'] == $aOffer['user_id']) {
                                 $error = $oPrj->ClearExecutor($aProject['id'], $nUid);
                             }
                             if (!$error) {
                                 $error = $oOffer->SetRefused($aOffer['id'], $aProject['id'], $aOffer['user_id'], '', true);
                             }
                             if ($error) {
                                 $this->error(EXTERNAL_ERR_SERVER_ERROR);
                             } else {
                                 $aOffer['refused'] = 't';
                             }
                             break;
                         case 2:
                             $error = false;
                             if ($aProject['exec_id'] == $aOffer['user_id']) {
                                 $error = $oPrj->ClearExecutor($aProject['id'], $nUid);
                             }
                             if (!$error) {
                                 $error = $oOffer->SetSelected($aOffer['id'], $aProject['id'], $aOffer['user_id'], true);
                             }
                             if ($error) {
                                 $this->error(EXTERNAL_ERR_SERVER_ERROR);
                             } else {
                                 $aOffer['selected'] = 't';
                             }
                             break;
                         case 3:
                             if ($oPrj->SetExecutor($aProject['id'], $aOffer['user_id'], $nUid)) {
                                 $this->error(EXTERNAL_ERR_SERVER_ERROR);
                             } else {
                                 $aOffer['exec_id'] = $aOffer['user_id'];
                             }
                             break;
                     }
                     $aResult = array('project_response' => $this->_getProjectOfferData($aOffer));
                 } else {
                     $this->error(EXTERNAL_ERR_PRJ_SELECTED);
                 }
             } else {
                 $this->error(EXTERNAL_ERR_OWNER);
             }
         } else {
             $this->error(EXTERNAL_ERR_PROJECT_NOT_FOUND);
         }
     } else {
         $this->error(EXTERNAL_ERR_OFFER_NOT_FOUND);
     }
     return $aResult;
 }