Exemplo n.º 1
0
page_ScriptNeed("instant_edit.js", "js");
global $GUI;
if (isset($_REQUEST["ref_system_flds_cfg"])) {
    if (isset($_POST["flds"])) {
        $_SESSION["user"]["data"]["conf_ref_system_fld"] = serialize($_POST["flds"]);
    } else {
        $_SESSION["user"]["data"]["conf_ref_system_fld"] = serialize(array());
    }
    Employee::update($_SESSION["user"]["data"]["id"], array('conf_ref_system_fld' => $_SESSION["user"]["data"]["conf_ref_system_fld"]));
    $_SESSION["ref_system_flds_cfg"] = true;
    $GUI->OK("Выполнено");
    die("");
}
$temp_table = 'referrer_system_' . $_SESSION["user"]["data"]["id"];
$query = "\n  SELECT o.*, ref.id AS referrer_id, ref.fio AS referrer_fio, ref.email AS referrer_email, ref.telnum AS referrer_phone, ref.city AS referrer_city, ref.referrer_code\n  FROM " . TBL_PREF . "orders o\n  JOIN " . TBL_PREF . "clients c ON c.id = o.klient_id\n  JOIN " . TBL_PREF . "clients ref ON ref.id = c.ref_id\n  WHERE c.ref_id != 0\n  ORDER BY o.id ASC\n";
db::query("CREATE TEMPORARY TABLE " . TBL_PREF . $temp_table . " AS (" . $query . ")");
//Search panel
$sp = $GUI->UPanel();
$sp->Caption = "Поиск партнера";
$searchWhere = '';
if (!empty($_REQUEST["kln_search"])) {
    $sp->defOpen = true;
    if (!empty($_REQUEST['search_id'])) {
        if (!empty($searchWhere)) {
            $searchWhere .= ' OR';
        }
        $searchWhere .= "referrer_id = '" . db::input($_REQUEST['search_id']) . "'";
    }
    if (!empty($_REQUEST['search_name'])) {
        if (!empty($searchWhere)) {
            $searchWhere .= ' OR';
function cron_sendEmailNotifications()
{
    $execution_time = ini_get('max_execution_time');
    if (empty($execution_time)) {
        $execution_time = DEF_EXEC_TIME;
    } else {
        if ($execution_time > MAX_EXEC_TIME * 2) {
            $execution_time = MAX_EXEC_TIME * 2;
        }
    }
    $execution_time_start = time();
    $execution_time_end = $execution_time_start + $execution_time / 2;
    $notifications = \Components\Entity\EmailNotification::findBy(array(), array('attempts_to_send' => 'ASC'), EMAIL_NOTIFICATION_LIMIT, 0);
    $notification_index = 0;
    $good_cnt = 0;
    $notification_count = count($notifications);
    while (time() <= $execution_time_end && $notification_index < $notification_count) {
        $notification = $notifications[$notification_index];
        $message = \Components\Entity\Message::find($notification['message_id']);
        if (!empty($message)) {
            //Прочитано, или не шлем - надо его сразу убить, чтобы потом когда включим не повалил шквал старых писем
            if ($message['readed'] || !\Components\Entity\EmailNotificationType::isSendable($notification['type'])) {
                \Components\Entity\EmailNotification::delete($notification['id']);
            } else {
                $attachments = array();
                // надо только для писем типа \Components\Entity\EmailNotification::TO_SUBSCRIBED_AUTHORS_ON_DISTRIBUTION
                $all_added_size = 0;
                $fna = 0;
                if ($notification['type'] == \Components\Entity\EmailNotification::TO_SUBSCRIBED_AUTHORS_ON_DISTRIBUTION && !empty($message['order_id'])) {
                    $files = get_order_files($message['order_id']);
                    foreach ($files as $file) {
                        $all_added_size += $file['size'];
                        if ($all_added_size > 16000000) {
                            // write to body, but not add file
                            $fna++;
                        } else {
                            $attachments[] = array('path' => get_file_path($message['order_id'], $file), 'name' => $file['name']);
                        }
                    }
                }
                $subtext = "";
                if ($fna) {
                    $subtext = "<br><br>-----------------------------------<br>" . "Еще " . $fna . " файла(ов) не были добавлены к письму из-за ограничения размеров";
                }
                // Это условие проверено выше
                //if ( \Components\Entity\EmailNotificationType::isSendable($notification['type']) )
                //{
                $email = new \Components\Classes\Email();
                $email->IsHTML(true);
                $email->setData(array('email' => $notification['receiver_email'], 'name' => ''), $message['subject'], $message['text'] . $subtext, $attachments, true, Message::getReceiverEmailAndName($message['creator_id']), Message::getReceiverEmailAndName($message['creator_id']));
                try {
                    $send_result = $email->send();
                    if ($send_result) {
                        \Components\Entity\EmailNotification::delete($notification['id']);
                        $good_cnt++;
                    } else {
                        \Components\Entity\EmailNotification::update($notification['id'], array('attempts_to_send' => $notification['attempts_to_send'] + 1, 'last_attempt' => time(), 'last_error' => $email->ErrorInfo));
                    }
                } catch (\Components\Exceptions\Exception $e) {
                    \Components\Entity\EmailNotification::update($notification['id'], array('attempts_to_send' => $notification['attempts_to_send'] + 1, 'last_attempt' => time()));
                }
                unset($email);
                //}
            }
        }
        $notification_index++;
    }
    db::query("update ofc_sys_log set p_value=" . $execution_time_start . " where p_name='email_notify_last_tm_start'");
    db::query("update ofc_sys_log set p_value=" . (time() - $execution_time_start) . " where p_name='email_notify_last_tm_work'");
    db::query("update ofc_sys_log set p_value=" . $notification_index . " where p_name='email_notify_last_all_cnt'");
    db::query("update ofc_sys_log set p_value=" . $good_cnt . " where p_name='email_notify_last_good_cnt'");
}
Exemplo n.º 3
0
/**
 * @deprecated
 * @param $user_id
 * @return bool
 */
function is_manager($user_id)
{
    if (db::num_rows(db::query("\n    SELECT *\n    FROM " . TBL_PREF . "data_users u\n    JOIN " . TBL_PREF . "roles r ON u.group_id = r.id\n    WHERE (r.name = 'Старший менеджер' OR r.name = 'Менеджер' OR r.name = 'Младший менеджер') AND u.id = " . db::input($user_id) . "\n  "))) {
        return true;
    }
    return false;
}
Exemplo n.º 4
0
function deluser_exec($Frm, $Err)
{
    if (!$Err) {
        if (is_director($_SESSION["user"]['data']['id'])) {
            $id = $Frm->GetNmValueI('id');
            if (count(Order::findBy(array('manager_id' => $id)))) {
                $Frm->_gui->informer->ERR("У сотрудника есть назначенные заказы");
                return;
            }
            if (db::get_single_value("SELECT COUNT(id) FROM " . TBL_PREF . "data_visits WHERE user_id = '" . $id . "' AND status <> 1")) {
                $Frm->_gui->informer->ERR("У сотрудника есть назначенные встречи");
                return;
            }
            $resone = $Frm->GetNmValueH('reason');
            db::query("insert into " . TABLE_USERS_BLACK . " select * from " . TABLE_USERS . " where id= " . $id);
            EmployeeBlack::update($id, array('comments' => $resone, 'blocked' => 1, 'black_list' => 1, 'removed_by' => $_SESSION['user']['data']['id'], 'removed_time' => time()));
            Employee::delete($id);
            $Frm->_gui->informer->OK("Сотрудник перенесен в черный список");
        } else {
            $Frm->_gui->informer->ERR("Перемещать сотрудников в черный список может только руководитель");
        }
        page_reloadSec();
    }
}