121 lines
3.6 KiB
PHP
121 lines
3.6 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
|
|
$userId = $_SESSION[id];
|
|
|
|
$user = new User;
|
|
$user->get($userId);
|
|
|
|
$data = json_decode(file_get_contents("php://input"));
|
|
|
|
$selector = 'req-new-funnel';
|
|
$section = '';
|
|
if(isset($data->selector)){
|
|
$selector = $data->selector;
|
|
}
|
|
if(isset($data->section)){
|
|
$section = $data->section;
|
|
}
|
|
|
|
$arrayFunnel = array();
|
|
$arrayOrder = array();
|
|
$arrayId = array();
|
|
|
|
?>
|
|
<select id="<?=$selector?>" name="<?=$selector?>" data-load-once="true" <?=($selector == 'filter_charts_funnel') ? 'multiple' : ''?>>
|
|
<?php
|
|
if ($user->agencyId != 6841 && $user->agencyId != 6426 && $user->agencyId != 7384 && $user->agencyId != 7478 && $user->agencyId != 8353 && $user->agencyId != 8867 && $user->agencyId != 9588) {
|
|
$useCustomFunnel = true;
|
|
} else {
|
|
$useCustomFunnel = false;
|
|
}
|
|
$nameDefault = "Обычные";
|
|
$rCastom = array('id' => 0, 'name' => 'Обычные', 'is_client' => 1, 'is_req' => 1, 'is_stage' => 1, 'is_show_funnels' => 1, 'order_number' => 0);
|
|
$sqlCastom = "SELECT * FROM funnel_default WHERE agency_id = {$user->agencyId}";
|
|
if($section == 'req'){
|
|
$sqlCastom = "SELECT * FROM funnel_default WHERE agency_id = {$user->agencyId}";
|
|
}
|
|
$qCastom = mysql_query($sqlCastom);
|
|
if(mysql_num_rows($qCastom) > 0){
|
|
$rCastom = mysql_fetch_assoc($qCastom);
|
|
$rCastom['id'] = 0;
|
|
if(!empty($rCastom['name'])){
|
|
$nameDefault = $rCastom['name'];
|
|
}
|
|
if($section == 'client'){
|
|
if($rCastom['is_client'] == 0){
|
|
$useCustomFunnel = false;
|
|
}
|
|
}
|
|
if($section == 'req'){
|
|
if($rCastom['is_req'] == 0){
|
|
$useCustomFunnel = false;
|
|
}
|
|
}
|
|
}
|
|
if($useCustomFunnel) {
|
|
$arrayFunnel[] = $rCastom;
|
|
?>
|
|
|
|
<?php
|
|
}
|
|
$sql = "select * from funnel WHERE agency_id = {$user->agencyId} and deleted=0";
|
|
if($section == 'client'){
|
|
$sql .= " and is_client = 1";
|
|
} else if ($section == 'req'){
|
|
$sql .= " and is_req = 1";
|
|
}
|
|
$sql .= " order by id";
|
|
|
|
$funnelsData = mysql_query($sql);
|
|
|
|
$i = 0;
|
|
|
|
while($funnel = mysql_fetch_assoc($funnelsData)) {
|
|
|
|
$arrNoSeeUsers = array();
|
|
$is_see = true;
|
|
if($funnel['is_no_see']==1 && !empty($funnel['users_no_see'])){
|
|
$tempArrNoSee = json_decode($funnel['users_no_see'], true);
|
|
foreach($tempArrNoSee as $u){
|
|
if(strpos($u, 'all_') !== false){
|
|
$manId = str_replace('all_', '', $u);
|
|
$sql_u = "SELECT id FROM `users`
|
|
WHERE id = $manId OR
|
|
id_manager = $manId OR
|
|
id_manager IN (SELECT id FROM users WHERE id_manager = $manId)";
|
|
$q_u = mysql_query($sql_u);
|
|
while($r_u = mysql_fetch_row($q_u)){
|
|
$arrNoSeeUsers[] = (int)$r_u[0];
|
|
}
|
|
} else {
|
|
$arrNoSeeUsers[] = (int)$u;
|
|
}
|
|
}
|
|
}
|
|
if($funnel['is_no_see'] == 1 && !empty($funnel['users_no_see'])){
|
|
$is_see = false;
|
|
if(in_array($userId, $arrNoSeeUsers)){
|
|
$is_see = true;
|
|
}
|
|
}
|
|
//$funnel['arr_no_see'] = $arrNoSeeUsers;
|
|
if($is_see){
|
|
$arrayFunnel[] = $funnel;
|
|
}
|
|
}
|
|
|
|
foreach($arrayFunnel as $key=>$funnel){
|
|
$arrayOrder[$key]=$funnel['order_number'];
|
|
$arrayId[$key]=$funnel['id'];
|
|
}
|
|
array_multisort($arrayOrder, SORT_ASC, $arrayId, SORT_ASC, $arrayFunnel);
|
|
|
|
foreach($arrayFunnel as $key => $funnel){
|
|
?>
|
|
<option value="<?=$funnel['id']?>"><?=$funnel['name']?></option>
|
|
<?php
|
|
}
|
|
|
|
?>
|
|
</select>
|