nakljucno, 1->fiksno, 2->po abecedi padajoce, 3->po abecedi narascajoce) var $isAnketar = false; var $telephoneSprId = null; private $inv_variables = array('email','password','ime','priimek','naziv','telefon','drugo'); private $inv_variables_link = array('email'=>'email','geslo'=>'password','ime'=>'firstname','priimek'=>'lastname','naziv'=>'salutation','telefon'=>'phone','drugo'=>'custom','last_status'=>'last_status','sent'=>'sent','responded'=>'responded','unsubscribed'=>'unsubscribed'); function __construct($sid) { $this->sid = $sid; SurveyInfo::SurveyInit($this->sid); $this->surveySettings = SurveyInfo::getInstance()->getSurveyRow(); SurveyDataSettingProfiles :: Init($this->sid); $sql = sisplet_query("SELECT * FROM srv_telephone_setting WHERE survey_id = '$this->sid'"); $row = mysqli_fetch_array($sql); if (mysqli_num_rows($sql) > 0) { $this->status_z = $row['status_z']; $this->status_n = $row['status_n']; $this->status_d = $row['status_d']; $this->max_calls = $row['max_calls']; $this->call_order = $row['call_order']; } $this->telephoneSprId = $this->get_spr_telefon_id(); # če spremenljivka telefon ne obstaja jo dodamo if ((int)$this->telephoneSprId == 0) { $sys = $this->addSystemVariables(array('inv_field_phone')); $this->telephoneSprId = $sys['telefon']; } $d = new Dostop(); $this->isAnketar = $d->isAnketar(); # počistimo polja if (isset($_POST['recipients_list']) && $_POST['recipients_list'] != null) { $_POST['recipients_list'] = mysql_real_unescape_string($_POST['recipients_list']); } if (isset($_POST['fields']) && $_POST['fields'] != null) { $_POST['fields'] = mysql_real_unescape_string($_POST['fields']); } } function ajax() { if (isset($_REQUEST['m']) && trim($_REQUEST['m']) != '') { $this->action($_REQUEST['m']); } else { echo 'Ajax error!'; return 'Ajax error!'; } } function action($action) { $NoNavi = false; if (isset($_POST['noNavi']) && $_POST['noNavi'] == 'true') { $NoNavi = true; } if ($NoNavi == false ) { echo '
'; } if ($action == 'recipients_lists') { $this->recipientsLists(); } else if ($action == 'view_recipients') { $this->viewRecipients(); } else if ($action == 'start_call') { $this->startCall(); } else if ($action == 'call') { $this->Call(); } else if ($action == 'settings') { $this->settings(); } else if ($action == 'settings_save') { $this->settingsSave(); $this->settings(); } else if ($action == 'calling_list') { $this->callingList(); } else if ($action == 'setSortField') { $this->setSortField(); } else if ($action == 'set_recipient_filter') { $this->setRecipientFilter(); } else if ($action == 'addmark') { $this->addMark(); } else if ($action == 'preveriStevilkeTimer') { $this->preveriStevilkeTimer(); } else if ($action == 'setNextAction') { $this->setNextAction(); } else if ($action == 'addRecipients') { $result = $this->addRecipients(); # prikažemo napake $invalid_recipiens_array = $this->displayRecipentsErrors($result); $this->viewRecipients(); } else if ($action == 'setUserComment') { $this->setUserComment(); } else if ($action == 'deleteProfile') { $this->deleteProfile(); } else if ($action == 'editProfile') { $this->editProfile(); } else if ($action == 'updateProfile') { $this->updateProfile(); } else if ($action == 'getProfileName') { $this->getProfileName(); } else if ($action == 'saveNewProfile') { $this->saveNewProfile(); } else if ($action == 'saveProfile') { $attributes = array(); if (isset($_POST['pid'])) { $attributes['pid'] = $_POST['pid']; } if (isset($_POST['fields'])) { $attributes['fields'] = str_replace('inv_field_','',implode(',',$_POST['fields'])); } if (isset($_POST['recipients_list'])) { $attributes['recipients'] = mysql_real_unescape_string($_POST['recipients_list']); } $this->saveProfile($attributes); } else if ($action == 'goToUser') { $this->goToUser(); } else if ($action == 'startSurvey') { $this->startSurvey(); } else if ($action == 'showPopupAddMarker') { $this->showPopupAddMarker(); } else if ($action == 'undoLastStatus') { $this->undoLastStatus(); } else { $this->showTelephoneStatus(); } } function showTelephoneStatus() { global $lang, $site_url; # polovimo statuse respondentov # skreiramo query s katerim polovimo userje in pripadajoče sistemske podatke $str_fields[] = " u.id AS usr_id"; $str_fields[] = " u.phone"; $str_fields[] = " u.last_status as status"; $str_joins[] = " srv_invitations_recipients as u"; $str_conditions[] = " u.ank_id = '$this->sid'"; $str_conditions[] = " u.deleted ='0'"; $str_conditions[] = " TRIM(u.phone) !=''"; # pripravimo ostale join in condtion stavke # polovimo še iz baze klicev, vse trenutno začete klice $str_fields[] = " scc.rec_id AS sccusr"; $str_joins[] = " LEFT OUTER JOIN (SELECT rec_id FROM srv_telephone_current) AS scc ON scc.rec_id = u.id"; # polovimo še iz baze klicev, zadnji statuse $str_fields[] = " sch.status AS schstatus"; $str_fields[] = " sch.user_id AS user_id"; $str_fields[] = " sch.insert_time AS insert_time"; $str_joins[] = " LEFT OUTER JOIN (SELECT rsch.status, rsch.rec_id, rsch.user_id, rsch.insert_time FROM srv_telephone_history AS rsch INNER JOIN (SELECT MAX(id) as iid, rec_id FROM srv_telephone_history GROUP BY rec_id) as insch ON insch.iid = rsch.id) AS sch ON sch.rec_id = u.id"; # join za pregled po anketarjih $str_fields[] = " usr.id AS usrid"; $str_joins[] = " LEFT OUTER JOIN (SELECT id FROM users) AS usr ON usr.id = sch.user_id"; # zložimo query $str_qry_users = "SELECT ".implode(',', $str_fields)." FROM ".implode(' ',$str_joins)." WHERE ".implode(' AND',$str_conditions); # sortiramo po statusih $statusi = array(); $statusi_anketar = array(); $contacted = 0; $qry = sisplet_query($str_qry_users); if (!$qry) echo mysqli_error($GLOBALS['connect_db']); if (mysqli_num_rows($qry)) { // Filter na datum echo ''.$lang['srv_telephone_no_respondents'].'
'; } } function recipientsLists() { if (isset($_POST['pid'])) { $pid = (int)$_POST['pid']; } else { $pid = -1; } list($recipients_list,$fields) = $this->getRecipientsProfile($pid); $this->addRecipientsView($fields,$recipients_list); } function getRecipientsProfile($pid) { global $lang, $global_user_id; $fields = array(); $recipients_list=null; session_start(); # če ne obstaja začasen seznam ga naredimo (praznega) pid=-1 if (!isset($_SESSION['phn_rec_profile'][$this->sid])) { $_SESSION['phn_rec_profile'][$this->sid] = array( 'pid'=>-1, 'name'=>$lang['srv_invitation_new_templist'], 'fields'=>'phone', 'respondents'=>'', 'comment'=>$lang['srv_invitation_new_templist']); } #polovimo emaile in poljaiz seznama if ( $pid > 0) { # če imamo pid in je večji kot nič polovimo podatke iz tabele $sql_string = "SELECT fields,respondents FROM srv_invitations_recipients_profiles WHERE pid = '".$pid."'"; $sql_query = sisplet_query($sql_string); $sql_row = mysqli_fetch_assoc($sql_query); if (trim($sql_row['respondents']) != '') { $recipients_list = explode("\n",trim($sql_row['respondents'])); } $_fields = explode(",",$sql_row['fields']); if (count($_fields) > 0) { foreach ($_fields AS $field) { $fields[] = 'inv_field_'.$field; } } } else if ($pid == -1) { # začasen profil iz seje $_fields = explode(",",$_SESSION['phn_rec_profile'][$this->sid]['fields']); if (count($_fields) > 0) { foreach ($_fields AS $field) { $fields[] = 'inv_field_'.$field; } } if (trim($_SESSION['phn_rec_profile'][$this->sid]['respondents']) != '') { $recipients_list = explode("\n",trim($_SESSION['phn_rec_profile'][$this->sid]['respondents'])); } } else { $recipients_list[] = ''; $fields[]= 'inv_field_phone'; } return array($recipients_list,$fields); } function addRecipientsView( $fields = array(), $recipients_list=null) { #prikažemo vmesnik za dodajanje respondentov global $lang; echo ''.$lang['srv_inv_recipient_select_list'].'
'; $this->listRecipientsProfiles(); echo ''; foreach ($fields AS $fkey =>$field) { if ($field == 1) { if ($fkey == 'sent' || $fkey == 'responded' || $fkey == 'unsubscribed'){ #echo ' | '; echo ' | '.$lang['srv_telephone_respondents_'.$fkey].' | '; } else if ($fkey == 'ps_icon' ) { echo ''.$lang['srv_telephone_respondents_'.$fkey].' | '; } else if ($fkey == 'date_inserted' || $fkey == 'schedule_call_time' ) { echo ''.$lang['srv_telephone_respondents_'.$fkey].' | '; } else if ($fkey == 'schstatus' ) { echo ''.$lang['srv_telephone_respondents_'.$fkey].' | '; } else if ($fkey == 'last_status' ) { echo ''.$lang['srv_inv_recipients_last_status'].' | '; } else { echo ''.$lang['srv_telephone_respondents_'.$fkey].' | '; } } } echo '|||
---|---|---|---|---|---|---|---|---|---|---|
'.$cnt.' | '; foreach ($fields AS $fkey =>$field) { if ($field == 1) { switch ($fkey) { case 'ps_icon': echo ''; echo ''; echo ' | '; break; case 'last_status': echo ''; echo '('.$sql_row[$fkey].') - '.$lang['srv_userstatus_'.$sql_row[$fkey]].' | '; break; case 'inserted_uid': echo ''.$users[$row_users[$fkey]]['email'].' | '; break; case 'comment': echo '","\n",strip_tags($sql_row['comment'])).'">'; echo substr(strip_tags($sql_row['comment']),0,50).' | '; break; case 'date_inserted': case 'schedule_call_time': echo ''; echo $sql_row[$fkey].' | '; break; case 'inserted_uid': echo ''.$users[$sql_row[$fkey]]['email'].' | '; break; case 'schstatus': echo ''; echo $lang['srv_telephone_status_'.$sql_row[$fkey]]; echo ' | '; break; case 'email': echo ''; echo ''; if ($filter != '') { echo $this->hightlight($sql_row[$fkey],$filter); } else { echo $sql_row[$fkey]; } echo ''; echo ' | '; break; case 'list_id': echo ''; if ((int)$sql_row[$fkey] > 0) { if ($lists[$sql_row[$fkey]]['name'] != '') { echo ''.$lists[$sql_row[$fkey]]['name'].''; } else { echo $lang['srv_inv_recipient_list_deleted']; } } else { echo $lists[$sql_row[$fkey]]['name']; } echo ' | '; break; default: echo ''; if ($filter != '') { echo $this->hightlight($sql_row[$fkey],$filter); } else { echo $sql_row[$fkey]; } echo ' | '; break; } } } echo '
'; foreach ($fields AS $fkey =>$field) { if ($field == 1) { if ($fkey == 'sent' || $fkey == 'responded' || $fkey == 'unsubscribed'){ #echo ' | '; echo ' | '.$lang['srv_telephone_respondents_'.$fkey].' | '; } else if ($fkey == 'ps_icon' ) { echo ''.$lang['srv_telephone_respondents_'.$fkey].' | '; } else if ($fkey == 'date_inserted' || $fkey == 'schedule_call_time' ) { echo ''.$lang['srv_telephone_respondents_'.$fkey].' | '; } else if ($fkey == 'schstatus' ) { echo ''.$lang['srv_telephone_respondents_'.$fkey].' | '; } else if ($fkey == 'last_status' ) { echo ''.$lang['srv_inv_recipients_last_status'].' | '; } else { echo ''.$lang['srv_telephone_respondents_'.$fkey].' | '; } } } echo '|||
---|---|---|---|---|---|---|---|---|---|---|
'.$cnt.' | '; foreach ($fields AS $fkey =>$field) { if ($field == 1) { switch ($fkey) { case 'ps_icon': echo ''; echo ''; echo ' | '; break; case 'last_status': echo ''; echo '('.$sql_row[$fkey].') - '.$lang['srv_userstatus_'.$sql_row[$fkey]].' | '; break; case 'inserted_uid': echo ''.$users[$row_users[$fkey]]['email'].' | '; break; case 'comment': echo '","\n",strip_tags($sql_row['comment'])).'">'; echo substr(strip_tags($sql_row['comment']),0,50).' | '; break; case 'date_inserted': case 'schedule_call_time': echo ''; echo $sql_row[$fkey].' | '; break; case 'inserted_uid': echo ''.$users[$sql_row[$fkey]]['email'].' | '; break; case 'schstatus': echo ''; echo $lang['srv_telephone_status_'.$sql_row[$fkey]]; echo ' | '; break; case 'email': echo ''; echo ''; if ($filter != '') { echo $this->hightlight($sql_row[$fkey],$filter); } else { echo $sql_row[$fkey]; } echo ''; echo ' | '; break; case 'list_id': echo ''; if ((int)$sql_row[$fkey] > 0) { if ($lists[$sql_row[$fkey]]['name'] != '') { echo ''.$lists[$sql_row[$fkey]]['name'].''; } else { echo $lang['srv_inv_recipient_list_deleted']; } } else { echo $lists[$sql_row[$fkey]]['name']; } echo ' | '; break; default: echo ''; if ($filter != '') { echo $this->hightlight($sql_row[$fkey],$filter); } else { echo $sql_row[$fkey]; } echo ' | '; break; } } } echo '
'; /* * # uredi echo ' | '; # izbrisi echo ' | '; */ foreach ($fields AS $fkey =>$field) { if ($field == 1) { if ($fkey == 'sent' || $fkey == 'responded' || $fkey == 'unsubscribed'){ #echo ' | '; echo ' | addSortField($fkey).' class="anl_ac tbl_icon_'.$fkey.'" title="'.$lang['srv_telephone_respondents_'.$fkey].'">'.$lang['srv_telephone_respondents_'.$fkey].$this->addSortIcon($fkey).' | '; } else if ($fkey == 'ps_icon' ) { //echo 'addSortField($fkey).' class="anl_ac tbl_icon" title="'.$lang['srv_telephone_respondents_'.$fkey].'">'.$lang['srv_telephone_respondents_'.$fkey].$this->addSortIcon($fkey).' | '; } else if ($fkey == 'date_inserted' || $fkey == 'schedule_call_time' ) { echo 'addSortField($fkey).' class="anl_ac tbl_date pointer" title="'.$lang['srv_telephone_respondents_'.$fkey].'">'.$lang['srv_telephone_respondents_'.$fkey].$this->addSortIcon($fkey).' | '; } else if ($fkey == 'schstatus' ) { echo 'addSortField($fkey).' class="anl_ac pointer" title="'.$lang['srv_telephone_respondents_'.$fkey].'">'.$lang['srv_telephone_respondents_'.$fkey].$this->addSortIcon($fkey).' | '; } else if ($fkey == 'last_status' ) { echo 'addSortField($fkey).' class="anl_ac pointer" title="'.$lang['srv_inv_recipients_last_status'].'">'.$lang['srv_inv_recipients_last_status'].$this->addSortIcon($fkey).' | '; } else { echo 'addSortField($fkey).' class="pointer" title="'.$lang['srv_telephone_respondents_'.$fkey].'">'.$lang['srv_telephone_respondents_'.$fkey].$this->addSortIcon($fkey).' | '; } } } echo '
---|---|---|---|---|---|---|---|---|---|
';
#izbriši
echo '';
#uredi
echo '';
foreach ($fields AS $fkey =>$field) {
if ($field == 1) {
switch ($fkey) {
case 'ps_icon':
echo '';
echo ' | ';
break;
case 'last_status':
echo ''; echo '('.$sql_row[$fkey].') - '.$lang['srv_userstatus_'.$sql_row[$fkey]].' | '; break; case 'inserted_uid': echo ''.$users[$row_users[$fkey]]['email'].' | '; break; case 'comment': echo '","\n",strip_tags($sql_row['comment'])).'">'; /*echo substr(strip_tags($sql_row['comment']),0,50).' | ';*/ if ($filter != '') { echo $this->hightlight(substr(strip_tags($sql_row['comment']),0,50),$filter); } else { echo substr(strip_tags($sql_row['comment']),0,50); } echo ''; break; case 'date_inserted': case 'schedule_call_time': echo ''; echo $sql_row[$fkey].' | '; break; case 'inserted_uid': echo ''.$users[$sql_row[$fkey]]['email'].' | '; break; case 'schstatus': echo ''; echo $lang['srv_telephone_status_'.$sql_row[$fkey]]; echo ' | '; break; case 'email': echo ''; echo ''; if ($filter != '') { echo $this->hightlight($sql_row[$fkey],$filter); } else { echo $sql_row[$fkey]; } echo ''; echo ' | '; break; case 'list_id': echo ''; if ((int)$sql_row[$fkey] > 0) { if ($lists[$sql_row[$fkey]]['name'] != '') { echo ''.$lists[$sql_row[$fkey]]['name'].''; } else { echo $lang['srv_inv_recipient_list_deleted']; } } else { echo $lists[$sql_row[$fkey]]['name']; } echo ' | '; break; default: echo ''; if ($filter != '') { echo $this->hightlight($sql_row[$fkey],$filter); } else { echo $sql_row[$fkey]; } echo ' | '; break; } } } echo '
'.$lang['srv_call_nextcall'].': '.datetime($row1['call_time']).'
'; else echo ''.$lang['srv_call_nonumbers'].'
'; echo ''; } } /** * @desc vrne naslednji row s stevilko za klic */ function get_next_number () { global $global_user_id; # najprej pogledamo ce je kaksen v srv_telephone_current - mor ga obvezno razresiti ker je zaklenjen $sel = "SELECT srv_invitations_recipients.id AS usr_id, TRIM(srv_invitations_recipients.phone) AS text" ." FROM srv_telephone_current LEFT JOIN srv_invitations_recipients ON srv_telephone_current.rec_id = srv_invitations_recipients.id " ." WHERE srv_invitations_recipients.ank_id ='$this->sid'" ." AND srv_invitations_recipients.deleted ='0'" ." AND srv_telephone_current.user_id = $global_user_id" ." AND srv_telephone_current.rec_id = srv_invitations_recipients.id" ." AND TRIM(srv_invitations_recipients.phone) != ''" ." AND srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)" ." ORDER BY srv_invitations_recipients.id ASC" ." LIMIT 1"; $sql = sisplet_query($sel); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); if (mysqli_num_rows($sql) > 0) { return mysqli_fetch_array($sql); } // najprej selectamo, tiste ki so zmenjeni po urniku $sel = "SELECT srv_invitations_recipients.id AS usr_id, TRIM(srv_invitations_recipients.phone) AS text, '1' AS schedule" ." FROM srv_telephone_schedule LEFT JOIN srv_invitations_recipients ON srv_telephone_schedule.rec_id = srv_invitations_recipients.id " ." WHERE srv_invitations_recipients.ank_id ='$this->sid'" ." AND srv_invitations_recipients.deleted ='0'" ." AND srv_telephone_schedule.rec_id = srv_invitations_recipients.id" ." AND TRIM(srv_invitations_recipients.phone) != ''" ." AND srv_telephone_schedule.call_time <= NOW()" ." AND srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_current.rec_id" ." FROM srv_telephone_current" ." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT DISTINCT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." GROUP BY srv_telephone_history.rec_id" ." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'" ." )" ." ORDER BY srv_telephone_schedule.call_time ASC" ." LIMIT 1"; $sql = sisplet_query($sel); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); if (mysqli_num_rows($sql) > 0) { return mysqli_fetch_array($sql); } // ce ni nobenega na urniku pa nadaljujemo z random izbiro ostalih stevilk /* fetch random from available * exclude from fetch: * - all phones which are currently active * - all phones which are on the schedule for the future * - all phones which have "R" or "U" status * - all phones which are called more that "max_calls" setting */ // Sortiranje if($this->call_order == 1) $order_by = ' srv_invitations_recipients.id ASC'; elseif($this->call_order == 2) $order_by = ' srv_invitations_recipients.firstname ASC, srv_invitations_recipients.lastname ASC, srv_invitations_recipients.email ASC, srv_invitations_recipients.id ASC'; elseif($this->call_order == 3) $order_by = ' srv_invitations_recipients.firstname DESC, srv_invitations_recipients.lastname DESC, srv_invitations_recipients.email DESC, srv_invitations_recipients.id DESC'; else $order_by = ' RAND()'; $sel = "SELECT srv_invitations_recipients.id AS usr_id, TRIM(srv_invitations_recipients.phone) AS text, '0' AS schedule" ." FROM srv_invitations_recipients" ." WHERE srv_invitations_recipients.ank_id ='$this->sid'" ." AND srv_invitations_recipients.deleted ='0'" ." AND TRIM(srv_invitations_recipients.phone) != ''" ." AND srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_current.rec_id" ." FROM srv_telephone_current" ." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_schedule.rec_id" ." FROM srv_telephone_schedule" ." WHERE srv_telephone_schedule.call_time > NOW()" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." GROUP BY srv_telephone_history.rec_id" ." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'" ." )" ." ORDER BY ".$order_by."" ." LIMIT 1"; $sql = sisplet_query($sel); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); return mysqli_fetch_array($sql); } /** * @desc vrne vse stevilke ki se trenutno klicejo (s pravim vrstnim redom) */ function getAllNumbers () { global $global_user_id; $result = array(); # najprej pogledamo ce je kaksen v srv_telephone_current - mor ga obvezno razresiti ker je zaklenjen $sel = "SELECT srv_invitations_recipients.id, TRIM(srv_invitations_recipients.phone) AS phone" ." FROM srv_telephone_current LEFT JOIN srv_invitations_recipients ON srv_telephone_current.rec_id = srv_invitations_recipients.id " ." WHERE srv_invitations_recipients.ank_id ='$this->sid'" ." AND srv_invitations_recipients.deleted ='0'" ." AND srv_telephone_current.user_id = $global_user_id" ." AND srv_telephone_current.rec_id = srv_invitations_recipients.id" ." AND TRIM(srv_invitations_recipients.phone) != ''" ." AND srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)" ." ORDER BY srv_invitations_recipients.id ASC"; $sql = sisplet_query($sel); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); if (mysqli_num_rows($sql) > 0) { while ( list($id,$phone) = mysqli_fetch_row($sql)) { $result[$id] = $phone; } } # najprej selectamo, tiste ki so zmenjeni po urniku $sel = "SELECT srv_invitations_recipients.id, TRIM(srv_invitations_recipients.phone) AS phone" ." FROM srv_telephone_schedule LEFT JOIN srv_invitations_recipients ON srv_telephone_schedule.rec_id = srv_invitations_recipients.id " ." WHERE srv_invitations_recipients.ank_id ='$this->sid'" ." AND srv_invitations_recipients.deleted ='0'" ." AND srv_telephone_schedule.rec_id = srv_invitations_recipients.id" ." AND TRIM(srv_invitations_recipients.phone) != ''" ." AND srv_telephone_schedule.call_time <= NOW()" ." AND srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_current.rec_id" ." FROM srv_telephone_current" ." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT DISTINCT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." GROUP BY srv_telephone_history.rec_id" ." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'" .")" ." ORDER BY srv_invitations_recipients.id ASC"; $sql = sisplet_query($sel); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); if (mysqli_num_rows($sql) > 0) { while ( list($id,$phone) = mysqli_fetch_row($sql)) { $result[$id] = $phone; } } # ce ni nobenega na urniku pa nadaljujemo z random izbiro ostalih stevilk /* fetch random from available * exclude from fetch: * - all phones which are currently active * - all phones which are on the schedule for the future * - all phones which have "R" or "U" status * - all phones which are called more that "max_calls" setting */ // Sortiranje if($this->call_order == 1) $order_by = ' srv_invitations_recipients.id ASC'; elseif($this->call_order == 2) $order_by = ' srv_invitations_recipients.firstname ASC, srv_invitations_recipients.lastname ASC, srv_invitations_recipients.email ASC, srv_invitations_recipients.id ASC'; elseif($this->call_order == 3) $order_by = ' srv_invitations_recipients.firstname DESC, srv_invitations_recipients.lastname DESC, srv_invitations_recipients.email DESC, srv_invitations_recipients.id DESC'; else $order_by = ' RAND()'; $sel = "SELECT srv_invitations_recipients.id, TRIM(srv_invitations_recipients.phone) AS phone" ." FROM srv_invitations_recipients " ." WHERE srv_invitations_recipients.ank_id ='$this->sid'" ." AND srv_invitations_recipients.deleted ='0'" ." AND TRIM(srv_invitations_recipients.phone) != ''" ." AND srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_current.rec_id" ." FROM srv_telephone_current" ." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_schedule.rec_id" ." FROM srv_telephone_schedule" ." WHERE srv_telephone_schedule.call_time > NOW()" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." GROUP BY srv_telephone_history.rec_id" ." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'" ." )" ."ORDER BY ".$order_by.""; $sql = sisplet_query($sel); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); if (mysqli_num_rows($sql) > 0) { while ( list($id,$phone) = mysqli_fetch_row($sql)) { $result[$id] = $phone; } } return $result; } /** * @desc vrne vse stevilke ki so na cakanju in bodo kasneje poklicane */ function getAllNumbersWaiting () { $result = array(); # selectamo, tiste ki so zmenjeni po urniku kasneje $sel = "SELECT srv_invitations_recipients.id, TRIM(srv_invitations_recipients.phone) AS phone" ." FROM srv_telephone_schedule LEFT JOIN srv_invitations_recipients ON srv_telephone_schedule.rec_id = srv_invitations_recipients.id " ." WHERE srv_invitations_recipients.ank_id ='$this->sid'" ." AND srv_invitations_recipients.deleted ='0'" ." AND srv_telephone_schedule.rec_id = srv_invitations_recipients.id" ." AND TRIM(srv_invitations_recipients.phone) != ''" ." AND srv_telephone_schedule.call_time > NOW()" ." AND srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_current.rec_id" ." FROM srv_telephone_current" ." WHERE srv_telephone_current.started_time >= DATE_SUB(NOW(), INTERVAL 2 HOUR)" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT DISTINCT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." WHERE srv_telephone_history.status = 'R' OR srv_telephone_history.status = 'U'" ." ) AND" ." srv_invitations_recipients.id NOT IN (" ." SELECT srv_telephone_history.rec_id" ." FROM srv_telephone_history" ." GROUP BY srv_telephone_history.rec_id" ." HAVING COUNT(srv_telephone_history.id) >= '$this->max_calls'" .")" ." ORDER BY srv_telephone_schedule.call_time ASC"; $sql = sisplet_query($sel); if (!$sql) echo mysqli_error($GLOBALS['connect_db']); if (mysqli_num_rows($sql) > 0) { while ( list($id,$phone) = mysqli_fetch_row($sql)) { $result[$id] = $phone; } } return $result; } function addMark($options = array()) { global $site_url,$global_user_id; if (is_array($options) && isset($options['usr_id']) && (int)$options['usr_id'] > 0) { $usr_id = $options['usr_id']; } else { $usr_id = $_GET['usr_id']; } if (is_array($options) && isset($options['status']) && (int)$options['status'] > 0) { $status = $options['status']; } else { $status = $_GET['status']; } if (is_array($options) && isset($options['datetime']) && (int)$options['datetime'] > 0) { $datetime = $options['status']; } else { $datetime = $_GET['datetime']; } if ($status != '') { sisplet_query("INSERT INTO srv_telephone_history (survey_id, user_id, rec_id, insert_time, status) VALUES ('$this->sid', '".$global_user_id."', '$usr_id', NOW(), '$status')"); } if ($status != 'A') { sisplet_query("DELETE FROM srv_telephone_current WHERE rec_id='$usr_id'"); } else { $s = sisplet_query("INSERT INTO srv_telephone_current (rec_id, user_id, started_time) VALUES ('$usr_id', '".$global_user_id."', NOW())"); if (!$s) echo mysqli_error($GLOBALS['connect_db']); } if ($status == 'Z') { $s = sisplet_query("INSERT INTO srv_telephone_schedule (rec_id, call_time) VALUES ('$usr_id', NOW() + INTERVAL $this->status_z MINUTE) ON DUPLICATE KEY UPDATE call_time = VALUES(call_time)"); if (!$s) echo mysqli_error($GLOBALS['connect_db']); } if ($status == 'N') { $s = sisplet_query("INSERT INTO srv_telephone_schedule (rec_id, call_time) VALUES ('$usr_id', NOW() + INTERVAL $this->status_n MINUTE) ON DUPLICATE KEY UPDATE call_time = VALUES(call_time)"); } if ($status == 'D') { $s = sisplet_query("INSERT INTO srv_telephone_schedule (rec_id, call_time) VALUES ('$usr_id', NOW() + INTERVAL $this->status_d MINUTE) ON DUPLICATE KEY UPDATE call_time = VALUES(call_time)"); } if ($status == 'T' || $status == 'P') { $datetime = substr($datetime,6,4).'-'.substr($datetime,3,2).'-'.substr($datetime,0,2).' '.substr($datetime,11,5).':00'; $s = sisplet_query("INSERT INTO srv_telephone_schedule (rec_id, call_time) VALUES ('$usr_id', '$datetime') ON DUPLICATE KEY UPDATE call_time = VALUES(call_time)"); } # če je zavrnil (R) potem izbrišemo morebitne zmenke if ($status == 'R' ) { sisplet_query("DELETE FROM srv_telephone_schedule WHERE rec_id='$usr_id'"); } #nardimo pravilne redirekte # ker imamo spodaj exit de ne izvede klasičen komit sisplet_query('COMMIT'); if ($status == 'A') { header("Location: index.php?anketa=$this->sid&a=".A_TELEPHONE."&m=call&usr_id=".$usr_id.'&status='.$status); exit(); } else { session_start(); if (isset($_SESSION['phnNextAction'][$this->sid]) && (int)$_SESSION['phnNextAction'][$this->sid] == '0') { # če je anketar je lako samo na klicanu if ($this->isAnketar) { header("Location: index.php?anketa=$this->sid&a=".A_TELEPHONE."&m=call"); #'&status='.$status exit(); } header("Location: index.php?anketa=$this->sid&a=".A_TELEPHONE."&m=view_recipients"); exit(); } else { header("Location: index.php?anketa=$this->sid&a=".A_TELEPHONE."&m=call"); #.'&status='.$status exit(); } } } function preveriStevilkeTimer () { $this->preveri_stevilke(); } function addRecipients() { global $global_user_id; $fields = $_POST['fields']; $_recipients = $_POST['recipients_list']; $recipients_list = str_replace("\n\r", "\n", $recipients_list); # povezava imena polji iz forem, z imeni polji v bazi $db_vs_form_array = array( 'inv_field_email' => 'email', 'inv_field_firstname' => 'firstname', 'inv_field_lastname' => 'lastname', 'inv_field_password' => 'password', 'inv_field_cookie' => 'cookie', 'inv_field_salutation' => 'salutation', 'inv_field_phone' => 'phone', 'inv_field_custom' => 'custom', ); $fields = $_POST['fields']; if (!is_array($fields)) { $fields = array(); } # katero polje je za password if (in_array('inv_field_password',$fields)) { $user_password = true; } else { $user_password = false; } #dodamo potrebna sistemska polja $this->addSystemVariables($fields); # dodamo ustrezne uporabnike, neustrezne izpišemo še enkrat da se lahko popravijo $_recipients = str_replace("\n\r", "\n", $_recipients); $recipients_list = explode("\n",$_recipients); $num_recipients_list = count($recipients_list); # katero polje je za e-mail if (in_array('inv_field_email',$fields)) { $user_email = true; } else { } # polje cookie mora bit zraven if (!in_array('inv_field_cookie',$fields)) { $fields[] = 'inv_field_cookie'; } # polovimo že dodane prejemnike iz baze $user_in_db = array(); $sql_string = "SELECT firstname,lastname,salutation,phone,custom FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted='0'"; $sql_query = sisplet_query($sql_string); if (mysqli_num_rows($sql_query) > 0 ) { while ($sql_row = mysqli_fetch_assoc($sql_query)) { $user_in_db[] = $sql_row['firstname'].$sql_row['lastname'].$sql_row['salutation'].$sql_row['phone'].$sql_row['custom']; } } # katero polje je za password if (in_array('inv_field_password',$fields)) { $user_password = true; } else { $user_password = false; # dodamo polje password $fields[] = 'inv_field_password'; } # polja za bazo $db_fields = ''; foreach ($fields as $field) { $db_fields .= ', '.$db_vs_form_array[$field]; } # katera gesla (code) že imamo v bazi za to anketo $password_in_db = array(); $sql_string = "SELECT password FROM srv_invitations_recipients WHERE ank_id = '".$this->sid."' AND deleted='0'"; $sql_query = sisplet_query($sql_string); while ($sql_row = mysqli_fetch_assoc($sql_query)) { $password_in_db[$sql_row['password']] = $sql_row['password']; } $unsubscribed = array(); /*polovimo prejemnike ki ne želijo prejemati obvestil $sql_string = "SELECT email FROM srv_invitations_recipients WHERE unsubscribed = '1'"; $sql_query = sisplet_query($sql_string); $unsubscribed = array(); if (mysqli_num_rows($sql_query) > 0 ) { while ($sql_row = mysqli_fetch_assoc($sql_query)) { $unsubscribed[] = $sql_row['email']; } }*/ #array z veljavnimi zapisi $valid_recipiens_array = array(); # array z zapisi kjer so napake v geslih $invalid_password_array = array(); #array z zapisi kjer so neveljavna gesla $invalid_email_array = array(); #array z podvojenimi zapisi $duplicate_email_array = array(); #aray z zapisi kjer so uporabniki izbrali da ne želijo prejemat e-mailov $unsubscribed_recipiens_array = array(); if ( $num_recipients_list > 0 ) { foreach ($recipients_list AS $recipient_line) { $recipient_line = trim($recipient_line); if ($recipient_line != null && $recipient_line != '') { $line_array = explode(',',$recipient_line); # predpostavljamo da je vrstica vredu $invalid_line = false; #prilagodimo izbrana polja $recipent_array = array(); $i = 0; foreach ($fields AS $field) { $recipent_array[$field] = $line_array[$i]; $i++; } # izvedemo validacijo posameznih polij # najprej preverimo gesla, če niso uporabniško določena, jih dodelimo sami if ( $invalid_line == false ) { # če še ni bilo napake ( da ne podvajamo zapisov pri katerih je več napak) if ($user_password == false) { # gesla določamo avtomatsko, (ne bo problemov :] ) # Izberemo random hash, ki se ni v bazi do { list($code,$cookie) = $this->generateCode(); } while (in_array($code,$password_in_db)); # polje za geslo je na zadnjem mestu (smo ga dodali zgoraj) $recipent_array['inv_field_password'] = $code; $recipent_array['inv_field_cookie'] = $cookie; # če je vse ok, geslo dodamo v seznam že uporabljenih $password_in_db[$code] = $code; } else { # gesla je določil uporabnik, (dajmo ga malo preverit) $user_password = trim($recipent_array['inv_field_password']); # preverimo ali je geslo že v bazi if ($user_password == null || $user_password == '' || in_array($user_password,$password_in_db)) { $invalid_password_array[] = $recipient_line; $invalid_line = true; } # če je vse ok, geslo dodamo v seznam že uporabljenih if ($invalid_line == false) { $password_in_db[$user_password] = $user_password; #dodamo še piškotek list($code,$cookie) = $this->generateCode(); $recipent_array['inv_field_cookie'] = $cookie; } } } # če imamo emaile naredimo validacijo, preverimo zavrnitve.. itd // if ($user_email == true && $invalid_line == false) { if ($invalid_line == false) { # # preberemo uporabniški email $email_field = trim($recipent_array['inv_field_firstname']) . trim($recipent_array['inv_field_lastname']) . trim($recipent_array['inv_field_salutation']) . trim($recipent_array['inv_field_phone']) . trim($recipent_array['inv_field_custom']); /* #ali je email veljaven if (!$this->validEmail($email_field) && $invalid_line == false) { $invalid_email_array[] = $recipient_line; $invalid_line = true; }*/ # ali je email podvojen if (in_array(strtolower($email_field),$user_in_db) && $invalid_line == false) { $duplicate_email_array[] = strtolower($recipient_line); $invalid_line = true; } /* ali uporabnik ne želi prejemati sporočil (opted out) if (in_array($email_field,$unsubscribed) && $invalid_line == false) { $unsubscribed_recipiens_array[] = $recipient_line; $invalid_line = true; }*/ # če je vse ok, email dodamo v seznam že uporabljenih if ( $invalid_line == false) { $user_in_db[] = $email_field; } } # če je vse ok dodamo userja k veljavnim if ( $invalid_line == false) { $valid_recipiens_array[] = $recipent_array; } } } } $list_id = (int)$_POST['pid']; # pripravimo sql stavek za vstavljanje if (count($valid_recipiens_array ) > 0) { $sql_insert_start = "INSERT INTO srv_invitations_recipients (ank_id".$db_fields.",sent,responded,unsubscribed,deleted,date_inserted,inserted_uid,list_id) VALUES "; $count = 0; $sql_insert_array = array(); $cnt = 0; $max_in_array = 1000; # po koliko respondentov dodajamo naenkeat $array_loop = 0; foreach ( $valid_recipiens_array AS $recipent_fields) { $cnt++; $sql_insert = "('".$this->sid."'"; foreach ($recipent_fields as $field) { $sql_insert .= ", '$field'"; } $sql_insert .= ",'0','0','0','0',NOW(),'".$global_user_id."','".$list_id."')"; $sql_insert_array[$array_loop][] = $sql_insert; if ($cnt >= $max_in_array) { $array_loop++; $cnt = 0; } } $sql_insert_end = " ON DUPLICATE KEY UPDATE firstname=VALUES(firstname), lastname=VALUES(lastname), salutation=VALUES(salutation), phone=VALUES(phone), custom=VALUES(custom), deleted='0', date_inserted=NOW()"; # v loopu dodamo posamezne respondente po skupinah (ker kadar je respondentov veliko mysql crkne) if (count($sql_insert_array) > 0) { foreach ($sql_insert_array AS $sub_insert_array) { $query_insert = $sql_insert_start. implode(',',$sub_insert_array) .$sql_insert_end; $sqlQuery = sisplet_query($query_insert); $rows = mysqli_affected_rows($GLOBALS['connect_db']); if (!$sqlQuery) { $error = mysqli_error($GLOBALS['connect_db']); } } sisplet_query("COMMIT"); } } return array( 'valid_recipiens' => $valid_recipiens_array, 'invalid_password' => $invalid_password_array, 'invalid_email' => $invalid_email_array, 'duplicate_email' => $duplicate_email_array, 'unsubscribed' => $unsubscribed_recipiens_array); } function addSystemVariables($variables) { $user_base = 0; global $site_path; $system_fields = array( 'inv_field_email' => 'email', 'inv_field_firstname' => 'ime', 'inv_field_lastname' => 'priimek', # 'inv_field_password' => 'geslo', # gesla ne dodajamo kot sistemsko spremenljivko 'inv_field_salutation' => 'naziv', 'inv_field_phone' => 'telefon', 'inv_field_custom' => 'drugo', ); $variablesResult=array(); $sqlb = sisplet_query("SELECT branching, user_base FROM srv_anketa WHERE id = '".$this->sid."'"); $rowb = mysqli_fetch_array($sqlb); $ba = new BranchingAjax($this->sid); if (count($variables) > 0) { // zakaj je bi ta reverse??? //$variables = array_reverse($variables,true); foreach ($variables as $var) { if (isset($system_fields[$var])) { $spr_id = null; if (isset($system_fields[$var])) { $variable = $system_fields[$var]; } else { $variable = str_replace('inv_field_', '', $var); } $sqlVariable = sisplet_query("SELECT s.id FROM srv_spremenljivka s, srv_grupa g WHERE s.variable='".$variable."' AND s.gru_id=g.id AND g.ank_id='".$this->sid."'"); if (mysqli_num_rows($sqlVariable) == 0 && $variable!='pass') { // če varabla še ne obstaja jo kreiramo // za polje pass - Geslo ne kreiramo sistemske variable if ($variable != 'language') { $user_base = 1; } // dodamo novo spremenljivko na konec, tip je 21 ob_start(); $ba->ajax_spremenljivka_new(0, 0, 1, 0, 21); $spr_id = $ba->spremenljivka; ob_clean(); $s = sisplet_query("UPDATE srv_spremenljivka SET variable='".$variable."', variable_custom='1', naslov='".$variable."', sistem='1', visible='0' WHERE id='$spr_id'"); if (!$s) echo 'err435'.mysqli_error($GLOBALS['connect_db']); } else { list($spr_id) = mysqli_fetch_row($sqlVariable); } $variablesResult[$variable] = (int)$spr_id; } } } // če je potreben updejt (ampak najbrž je itak na 1 zaradi e-mail) if ($user_base > 0 && $user_base != $rowb['user_base']) { $sql = sisplet_query("UPDATE srv_anketa SET user_base='$user_base' WHERE id='" . $this->sid . "'"); SurveyInfo :: getInstance()->resetSurveyData(); } return $variablesResult; } function generateCode() { $cookie = md5(mt_rand(1, mt_getrandmax()) . '@' . $_SERVER['REMOTE_ADDR']); return array(substr($cookie,0,6), $cookie); } function displayRecipentsErrors($result) { global $lang; $valid_recipiens = is_array($result['valid_recipiens']) ? $result['valid_recipiens'] : array(); $invalid_password = is_array($result['invalid_password']) ? $result['invalid_password'] : array(); $insert_errors = is_array($result['insert_errors']) ? $result['insert_errors'] : array(); # dodani so bili nekateri uporabniki if (count($valid_recipiens) > 0) { echo ''.$lang['srv_inv_recipient_list_name'].' | '; echo ''; echo ''; echo ' |
'.$lang['srv_inv_recipient_list_comment'].' | '; echo ''; echo ''; echo ' |
'.$lang['srv_inv_recipient_list_recipients'].' | '; echo ''; echo ''; echo ' |