Exemple #1
0
 public function __construct()
 {
     parent::__construct();
     $this->load->model('node_model');
     $this->load->helper('date_convert_helper');
     // now
     $this->now = get_now();
 }
Exemple #2
0
function find_user($_id)
{
    //echo " ".$_id." ";
    global $facebook;
    $user = $facebook->api('/' . $_id);
    $params['last'] = get_now();
    $params['fb_uid'] = $user['id'];
    $params['link'] = $user['link'];
    $params['name'] = $user['name'];
    $params['username'] = $user['username'];
    $params['locale'] = $user['locale'];
    $params['name'] = $user['name'];
    $params['about'] = $user['about'];
    $params['birthday'] = date("Y-m-d", strtotime($user['birthday']));
    $params['gender'] = $user['gender'];
    $params['location'] = $user['location']['name'];
    $params['hometown'] = $user['hometown']['name'];
    $params['education'] = $user['education'][0]['school']['name'];
    $params['work'] = $user['work'][0]['employer']['name'] . '/' . $user['work'][0]['position']['name'];
    $params['relationship_status'] = $user['relationship_status'];
    if ($user['sports']) {
        foreach ($user['sports'] as $sp) {
            $sport .= " " . $sp['name'];
        }
        $params["sport"] = $sport;
    }
    if ($user['favorite_athletes']) {
        foreach ($user['favorite_athletes'] as $fa) {
            $favorite_athletes .= " " . $fa['name'];
        }
        $params["favorite_athletes"] = $favorite_athletes;
    }
    if ($user['favorite_teams']) {
        foreach ($user['favorite_teams'] as $ft) {
            $favorite_teams .= " " . $ft['name'];
        }
        $params["favorite_teams"] = $favorite_teams;
    }
    return $params;
}
Exemple #3
0
 public function get_calendar($calendar, $reload_url, $focus = null)
 {
     /* BENCHMARK */
     $this->benchmark->mark('func_get_calendar_start');
     $this->load->helper('data_helper');
     $this->load->model('slider_model');
     // default focus if not set
     if (null == $focus) {
         $focus = date('m-Y', time());
     }
     // get event array
     $events = json_decode($calendar['event_json'], true);
     // event nodes
     $event_nodes = $this->node_model->get_nodes(array('event.calendar_id' => $calendar['node_id'], 'type' => 'event'), 1);
     $this->event_nodes = $this->node_model->nodes_by_id($event_nodes);
     // set calendar into object and user, event default, colours etc
     $this->calendar = $calendar;
     $this->calendar['user'] = $this->node_model->get_node($this->calendar['user_id'], 'user');
     $event_default = $this->config->item('event_default');
     $this->colours = $event_default['colours'];
     // now
     $this->now = get_now();
     // break date
     $fdate_bits = date_bits($focus, '-');
     // get focus day and start of chunk
     $limit = array();
     if (is_numeric($focus)) {
         $cgran = 'year';
         $focus .= "0101";
         $limit['start'] = $focus;
         $sel_year = substr($limit['start'], 0, 4);
         $limit['end'] = $sel_year . "1232";
         // one day more than December this year will ensure only this year is output
     } elseif (8 == strlen($focus) or 7 == strlen($focus)) {
         $cgran = 'month';
         $month = is_numeric($fdate_bits[0]) ? $fdate_bits[0] : $this->month_names[strtolower($fdate_bits[0])];
         $focus = $fdate_bits[1] . $month . "01";
         $limit['start'] = $focus;
         $limit['end'] = substr($limit['start'], 0, 6) . "32";
         // one day more than any month will ensure only this month is output
     } elseif (10 == strlen($focus) or 11 == strlen($focus)) {
         $cgran = 'day';
         $month = is_numeric($fdate_bits[1]) ? $fdate_bits[1] : $this->month_names[strtolower($fdate_bits[1])];
         $focus = $fdate_bits[2] . $month . $fdate_bits[0];
         $limit['start'] = $focus;
         $limit['end'] = $limit['start'];
     } else {
         $cgran = 'month';
         $focus = str_replace('-', '', $this->now['string']);
         $limit['start'] = substr($focus, 0, 6) . "01";
         $limit['end'] = substr($focus, 0, 6) . "32";
         // one day more than any month will ensure only this month is output
     }
     // open the calendar
     $cale = '';
     $cal['meta_data'] = $calendar;
     $cal['granularity'] = $cgran;
     // back links
     $cal['back_links'] = array();
     if ('month' == $cgran) {
         // get bits
         $yf = $fdate_bits[1];
         // granularity links
         $cal['back_links']['year'] = "/" . $reload_url . "/" . $yf;
     } elseif ('day' == $cgran) {
         // get bits
         $yf = $fdate_bits[2];
         $mf = $fdate_bits[1] . '-' . $fdate_bits[2];
         // granularity links
         $cal['back_links']['year'] = "/" . $reload_url . "/" . $yf;
         $cal['back_links']['month'] = "/" . $reload_url . "/" . $mf;
     }
     // end limit
     // open the main calendar div
     // scroller
     // next and previous links
     $cal['next'] = array();
     $cal['previous'] = array();
     if ('day' == $cgran) {
         // open calendar
         $cale .= "<div id='day_chunk'>";
         // next and previous
         $y = substr($limit['start'], 0, 4);
         $m = substr($limit['start'], 4, 2);
         $d = substr($limit['start'], 6, 2);
         if ('01' == $d && '01' == $m) {
             $n = '02-01-' . $y;
             $l = '31-12-' . ($y - 1);
         } elseif ('31' == $d && '12' == $m) {
             $n = '01-01-' . ($y + 1);
             $l = '30-12-' . $y;
         } else {
             if ('01' == $d) {
                 $lm = $m - 1;
                 if ($lm < 10 ? $lm = '0' . $lm : ($lm = $lm)) {
                 }
                 $n = '02-' . $m . '-' . $y;
                 $l = days_in_month($m - 1, $y) . '-' . $lm . '-' . $y;
             } elseif ($d == days_in_month($m, $y)) {
                 $nm = $m + 1;
                 if ($nm < 10 ? $nm = '0' . $nm : ($nm = $nm)) {
                 }
                 $n = '01-' . $nm . '-' . $y;
                 $l = days_in_month($m, $y) - 1 . '-' . $m . '-' . $y;
             } else {
                 $nd = $d + 1;
                 $ld = $d - 1;
                 if ($nd < 10 ? $nd = '0' . $nd : ($nd = $nd)) {
                 }
                 if ($ld < 10 ? $ld = '0' . $ld : ($ld = $ld)) {
                 }
                 $n = $nd . '-' . $m . '-' . $y;
                 $l = $ld . '-' . $m . '-' . $y;
             }
         }
         // add next and previous
         $cal['next'] = array('link' => "/" . $reload_url . "/" . $n, 'label' => 'tomorrow');
         $cal['previous'] = array('link' => "/" . $reload_url . "/" . $l, 'label' => 'yesterday');
     } elseif ('month' == $cgran) {
         // open calendar
         $cale .= "<div id='month_chunk'>";
         // next and previous
         $y = substr($limit['start'], 0, 4);
         $m = substr($limit['start'], 4, 2);
         if (1 == $m) {
             // month name or num
             if (is_numeric($fdate_bits[0])) {
                 $nm = '02';
                 $lm = '12';
             } else {
                 $nm = 'feb';
                 $lm = 'dec';
             }
             $n = $nm . '-' . $y;
             $l = $lm . '-' . ($y - 1);
         } elseif (12 == $m) {
             // month name or num
             if (is_numeric($fdate_bits[0])) {
                 $nm = '01';
                 $lm = '11';
             } else {
                 $nm = 'jan';
                 $lm = 'nov';
             }
             $n = $nm . '-' . ($y + 1);
             $l = $lm . '-' . $y;
         } else {
             // month name or num
             if (is_numeric($fdate_bits[0])) {
                 $nm = $m + 1;
                 $lm = $m - 1;
                 if ($nm < 10 ? $nm = '0' . $nm : ($nm = $nm)) {
                 }
                 if ($lm < 10 ? $lm = '0' . $lm : ($lm = $lm)) {
                 }
             } else {
                 $nm = $this->month_nums[$m + 1];
                 $lm = $this->month_nums[$m - 1];
             }
             $n = $nm . '-' . $y;
             $l = $lm . '-' . $y;
         }
         // add next and previous
         $cal['next'] = array('link' => "/" . $reload_url . "/" . $n, 'label' => 'next month');
         $cal['previous'] = array('link' => "/" . $reload_url . "/" . $l, 'label' => 'last month');
     } elseif ('year' == $cgran) {
         // open calendar
         $cale .= "<div id='year_chunk'>";
         // next and previous
         $cal['next'] = array('link' => "/" . $reload_url . "/" . ($sel_year + 1), 'label' => 'next year');
         $cal['previous'] = array('link' => "/" . $reload_url . "/" . ($sel_year - 1), 'label' => 'last year');
     }
     // day names in convenient array
     $this->day_names = array('skip_zero', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
     // output chunk
     $cal['cells'] = array();
     foreach ($events as $k => $v) {
         if ($k >= $limit['start'] && $k <= $limit['end']) {
             $cal['cells'][$k] = $v;
             /*dev_dump($k);
               dev_dump($v);*/
             // date details
             /*    $y=substr($k,0,4);
                                     $m=substr($k,4,2);
                                     $d=substr($k,6,2);
                                     $ym=substr($k,0,6);
                                     $ymd=$k;
                                     $day_name=strtolower(format_date($y."-".$m."-".$d,'D'));
                                     $day_num=format_date($y."-".$m."-".$d,'N');
                                     $date=format_date($y."-".$m."-".$d,'d m Y');
                                     $link_date=$d."-".$m."-".$y;
             
                                 // open month
                                     if (in_array($cgran,array('year','month')) &&
                                         '01'==$d)
                                     {
                                         // open the month div
                                             $cale.="<div class='m'>";
             
                                         // if this is a year calendar then show a month name and link
                                             if ('year'==$cgran)
                                             {
                                                 if (1==$this->config->item('full_month_names') ? $mname=$this->month_nums['f'.$m] : $mname=$this->month_nums[$m] );
                                                 $cale.="<span class='mh'><a href='/".$reload_url."/".$this->month_nums[$m]."-".$y."'>".$mname."</a></span>";
                                             }
             
                                         // add a row of day names
                                             $cale.="<div class='dhs'>";
                                             $cale.="<span class='d dh mon'>mon</span>";
                                             $cale.="<span class='d dh tue'>tue</span>";
                                             $cale.="<span class='d dh wed'>wed</span>";
                                             $cale.="<span class='d dh thu'>thu</span>";
                                             $cale.="<span class='d dh fri'>fri</span>";
                                             $cale.="<span class='d dh sat'>sat</span>";
                                             $cale.="<span class='d dh sun'>sun</span>";
                                             $cale.="</div>";
             
                                         // fill the month output with dead cells
                                             for ($x=1;$x<$day_num;$x++)
                                             {
                                                 $cale.="<span class='d dc ".$this->day_names[$x]."'></span>";
                                             }
                                     }
             
                                 // open day and mark now (but not if its a day granularity, then we mark the half hour)
                                     if ( $k==$this->now['numeric'] && $cgran!='day' ? $extra_class=' now ' : $extra_class='' );
             
                                     // set a class if the day has visible events
                                         if (count($v['e'])>0)
                                         {
                                             foreach ($v['e'] as $check_id=>$val)
                                             {
                                                 if (1==$this->event_nodes[$check_id]['visible'])
                                                 {
                                                     $extra_class.='has_e';
                                                     break;
                                                 }
                                             }
                                         }
             
                                     $cale.="<div id='d".$ymd."' class='d ".$day_name." ".$extra_class."'>";
             
                                 // add exclusivity field
                                     $exs='';
                                     if (is_array($v['x']))
                                     {
                                         foreach ($v['x'] as $xk=>$xv)
                                         {
                                             $exs.=$xk.'-'.$xv.'_';
                                         }
                                     }
                                     $cale.="<input id='x".$ymd."' type='hidden' value='".$exs."'/>";
             
                                 // date
                                     if (isset($this->date_formats['calendar']) ? $date_text=date($this->date_formats['calendar'],strtotime($y."-".$m."-".$d)) : $date_text=$day_name." ".$date );
                                     if ('day'==$cgran)
                                     {
                                         $cale.="<span id='date_".$ymd."' class='master_date'>".$date_text."</span>";
                                     }
                                     elseif ('month'==$cgran)
                                     {
                                         if (0==$this->calendar['gran_link_through'])
                                         {
                                             $cale.="<span class='date'>".$date_text."</span>";
                                         }
                                         else
                                         {
                                             $cale.="<span class='date'><a href='/".$reload_url."/".$link_date."'>".$date_text."</a></span>";
                                         }
                                     }
                                     else
                                     {
                                         if (0==$this->calendar['gran_link_through'])
                                         {
                                             $cale.="<span class='date'>".day_suffix($d)."</span>";
                                         }
                                         else
                                         {
                                             $cale.="<span class='date'><a href='/".$reload_url."/".$link_date."'>".$d."</a></span>";
                                         }
                                     }
             
                                 // if the granularity is day by day then we break the day cell down further into half hours
                                 // we then iterate over the events inside this but the day by day calendar only hits the outer loop once
                                 // high detail calendars will be unusual and maybe a bit heavier to handle
                                     if ('day'==$cgran or
                                         1==$calendar['high_detail'])
                                     {
                                         // if marked as 'd' then all day - this may be the case for more than one event on this day so we must check all
                                             foreach ($v['e'] as $meta_id=>$day_event)
                                             {
                                                 // use zero to get the first array element - if it is 'd' (today) then there will only be one
                                                     if ('d'==$day_event['t'][0]['t'])
                                                     {
                                                         // output a cell
                                                             $cale.="<div id='allday_".$meta_id."' class='half_hour all_day'>";
                                                             $cale.="<span class='time'>all day</span>";
                                                             $cale.="</div>";
                                                     }
                                             }
             
                                         // now do all the half hour slots for the day
             
                                             foreach ($this->times as $t)
                                             {
                                                 // time as number
                                                     $tnum=str_replace(':','',$t['time']);
             
                                                 // highlight now
                                                     $extra_class=
                                                     (   $this->now['time_numeric']>=$tnum &&
                                                         $this->now['time_numeric']<=$tnum+29 &&
                                                         $this->now['numeric']==$k) ? ' now ' : '';
             
                                                 // open the half hour output slot - only if there is an event or its high detail
                                                     $cale.="<div id='time_".$tnum."' class='".$extra_class." time_".$tnum."'>";
                                                     $cale.="<span class='time'>".$t['label']."</span>";
                                                     $cale.="</div>";
                                             }
                                     }
                                     else
                                     {
                                         // events - just normal output for months
                                             if ('month'==$cgran)
                                             {
                                                 $view_link="";
                                                 $event_counter=0;
                                             }
                                             else
                                             {
                                                 $cale.="<a class='bview' href='/".$reload_url."/".$link_date."'>vw</a>";
                                             }
                                     }
             
                                 // close day
                                     $cale.="</div>";
             
                                 // close month
                                     if ($d==days_in_month($m,$y))
                                     {
                                         $cale.="</div>";
                                     }*/
         }
     }
     /* BENCHMARK */
     $this->benchmark->mark('func_get_calendar_end');
     return $cal;
 }
 public function admin_calendar($calendar)
 {
     /* BENCHMARK */
     $this->benchmark->mark('func_admin_calendar_start');
     $this->load->helper('date_helper');
     // get the array of date cells
     $cells = json_decode($calendar['event_json'], true);
     // get the default event
     $event_default = $this->config->item('event_default');
     // we need the colours from the event default
     $colours = $event_default['colours'];
     // mark today
     $now = get_now();
     // for breaking the calendar panels up
     $last_month = 0;
     $last_year = 0;
     // get the events sequences
     $events = $this->node_model->get_nodes(array('event.calendar_id' => $calendar['id'], 'type' => 'event'), 'joined');
     // order this array
     $es = array();
     foreach ($events as $e) {
         // count the number of nvars and infer the number of events in the sequence, skipping if there are none
         $query = $this->db->select('*')->from('nvar')->where(array('node_id' => $e['id']))->order_by('event_timestamp desc');
         $res = $query->get();
         $nvars = $res->result_array();
         if (count($nvars) > 0) {
             // get the first in the result and compare to now, if it's less then all this events
             // instances have passed
             $still_active = $nvars[0]['event_timestamp'] > $now['timestamp'] ? 1 : 0;
             // lol at the hack, array uses ids to differentiate between two events with the same name but hides it with css
             $es[$e['name'] . " <span style='display:none;'>[" . $e['id'] . "]</span>"] = array('id' => $e['id'], 'details' => $e, 'still_active' => $still_active);
         }
     }
     ksort($es);
     // output event sequences
     $acal = "<div class='panel events_list_panels'>";
     $acal . "<div class='calendar_events_list'>";
     $acal .= "<h2>";
     $acal .= "<span id='cal_events_heading' class='ad_heading_text noselect' onclick='open_height(\"cal_events\")'>Events On " . $calendar['name'] . "</span>";
     $acal .= "<span id='cal_events_show' class='sprite panel_open noselect' onclick='open_height(\"cal_events\")'></span>";
     $acal .= "</h2>";
     $acal .= "<div id='cal_events_panel' class='panel_details panel_closed'>";
     $acal .= "<span class='js_show_all_events all_event_link'>[show passed events too]</span>";
     $acal .= "<div class='cal_events_panel_list'>";
     foreach ($es as $name => $details) {
         $is_hidden = 0 == $details['still_active'] ? "class='passed hidden'" : "";
         $acal .= "<a " . $is_hidden . " href='/event/sequence/" . $details['id'] . "'>";
         $acal .= "<span id='hl_" . $details['id'] . "' class='event_meta_link' style='background-color:" . $colours[$details['details']['colour_choice']]['fill'] . ";border:1px solid " . $colours[$details['details']['colour_choice']]['border'] . "' onmouseover='event_hl(" . $details['id'] . ",\"" . $colours[$details['details']['colour_choice']]['fill'] . "\")' onmouseout='event_uhl(" . $details['id'] . ")'>";
         $acal .= $name . " [" . $details['details']['duration'] . "]";
         $acal .= "</span>";
         $acal .= "</a>";
     }
     $acal .= "</div>";
     $acal .= "</div>";
     $acal .= "</div>";
     // jquery function for highlight
     $js = '';
     $js .= "<script type='text/javascript'>";
     $js .= "function event_hl(id,colour)";
     $js .= "{";
     $js .= "\$('.hl_'+id).css({'opacity':'1'});";
     $js .= "\$('.hl_'+id+' span').css({'background-color':'#181818','color':'#fff','outline':'2px solid #181818'});";
     $js .= "}";
     $js .= "function event_uhl(id)";
     $js .= "{";
     if (strlen($this->config->item('admin_marked_colour')) > 0 ? $colour = $this->config->item('admin_marked_colour') : ($colour = '#f7f7f7')) {
     }
     $js .= "\$('.hl_'+id).css({'opacity':'0.75'});";
     $js .= "\$('.hl_'+id+' span').css({'background-color':'rgba(0,0,0,0)','color':'#181818','outline':'none'});";
     $js .= "}";
     $js .= "</script>";
     $acal .= $js;
     // build the form for the undoing of recent calendar updates
     $uf = '';
     /* $query=$this->db->select('step_sequence,description')->from('calendar_undo')->where(array('calendar_id'=>$calendar['id']))->order_by('step_sequence desc');
                 $res=$query->get();
                 $undos=$res->result_array();
     
                //$this->load->helper('form_helper');
                 $uf=form_open('/events/undo');
                 $uf.="<input type='hidden' name='calendar_id' value='".$calendar['id']."'/>";
                 $uf.="<select id='event_undos' class='form_field' name='undo'>";
                 foreach ($undos as $u)
                 {
                     $uf.="<option value='".$u['step_sequence']."'>".$u['description']."</option>";
                 }
                 $uf.="</select>";
                 $uf.="<input id='undo_submit' class='undo_submit' type='submit' name='submit' value='undo'/>";
                 $uf.="</form>"; */
     // open the panel divs
     $acal .= "<div class='panel all_previous_panel js_event_sweep'>";
     $acal .= "<h2>";
     $acal .= "<span id='previous_heading' class='ad_heading_text noselect' onclick='open_height(\"previous\")'>All Previous</span>";
     $acal .= "<span id='previous_show' class='sprite panel_open noselect' onclick='open_height(\"previous\")'></span>";
     $acal .= "</h2>";
     $acal .= "<div class='sweep_events'></div>";
     $acal .= "<div id='previous_panel' class='panel_details panel_closed'>";
     // build the calendar as an array of months and use the html slider
     $ps = array();
     $skip_first_close = true;
     //dev_dump($cells);
     foreach ($cells as $k => $v) {
         // break current cell key into numerics
         $key_date[0] = substr($k, 0, 4);
         $key_date[1] = substr($k, 4, 2);
         $key_date[2] = substr($k, 6, 2);
         $knum = $k;
         // keep the full numeric key for now calc
         $md = $key_date[1] . '-' . $key_date[2];
         $k = $key_date[0] . "-" . $key_date[1] . "-" . $key_date[2];
         // a new panel every three months
         if (in_array($md, array('01-01', '04-01', '07-01', '10-01'))) {
             // this panel is open
             $state = 'open';
             $extra_class = 'panel_closed';
             $now = date('Ymd', time());
             $key_plus = $key_date[0] . str_pad($key_date[1] + 2, 2, '0', STR_PAD_LEFT) . '31';
             if ($now > str_replace("-", "", $k) && $now < $key_plus) {
                 //$acal.=$now."|".$k."|".$key_plus."</div>";
                 $acal .= "</div>";
                 $acal .= "</div>";
                 $state = 'close';
                 $extra_class = '';
             }
             // open the panel divs
             $acal .= "<div class='panel js_event_sweep'>";
             $acal .= "<h2>";
             $acal .= "<span id='calendar_panel_" . $md . "-" . $key_date[0] . "_heading' class='ad_heading_text noselect' onclick='" . $state . "_height(\"calendar_panel_" . $md . "-" . $key_date[0] . "\")'>" . $this->month_nums[$key_date[1]] . " - " . $this->month_nums[$key_date[1] + 2] . " " . $key_date[0] . "</span>";
             $acal .= "<span id='calendar_panel_" . $md . "-" . $key_date[0] . "_show' class='sprite panel_" . $state . " noselect' onclick='" . $state . "_height(\"calendar_panel_" . $md . "-" . $key_date[0] . "\")'></span>";
             $acal .= "</h2>";
             $acal .= "<div class='sweep_events'></div>";
             $acal .= "<div id='calendar_panel_" . $md . "-" . $key_date[0] . "_panel' class='panel_details " . $extra_class . "'>";
         }
         // a new month means a new month div
         if ('01' == $key_date[2]) {
             // open month
             $acal .= "<div id='month_" . $key_date[0] . "-" . $key_date[1] . "' class='month'>";
             // heading
             $acal .= "<span class='mheading'>" . $this->month_nums[$key_date[1]] . "</span>";
             // add a row of day names
             $acal .= "<div id='day_headings'>";
             $acal .= "<span class='cal_cell day_heading'>mon</span>";
             $acal .= "<span class='cal_cell day_heading'>tue</span>";
             $acal .= "<span class='cal_cell day_heading'>wed</span>";
             $acal .= "<span class='cal_cell day_heading'>thu</span>";
             $acal .= "<span class='cal_cell day_heading'>fri</span>";
             $acal .= "<span class='cal_cell day_heading'>sat</span>";
             $acal .= "<span class='cal_cell day_heading'>sun</span>";
             $acal .= "</div>";
             // fill up the appropriate number of days with blanks so day columns are always the same
             $empty_cells = format_date($k, 'N') - 1;
             for ($x = 1; $x <= $empty_cells; $x++) {
                 $acal .= "<div class='empty_cell'>";
                 $acal .= "</div>";
             }
         }
         // today css
         if ($now['string'] == $k ? $today_cell = " now " : ($today_cell = "")) {
         }
         // passed css
         if ($knum < $now['numeric'] ? $passed = 'admincal_date_passed' : ($passed = '')) {
         }
         // get the day name for output
         $day_name = format_date($k, 'D');
         // now output the cell
         // add classes to date panel for highlight
         $extra_classes = '';
         $basic_mark_cell = 0;
         foreach ($v['e'] as $ek => $ev) {
             $basic_mark_cell++;
             $extra_classes .= " hl_" . $ek;
         }
         // mark all cells that have any number of events
         if ($basic_mark_cell > 0 ? $mark_class = ' marked ' : ($mark_class = '')) {
         }
         // open
         //$acal.="<div id='day_".$k."' class='cal_cell ".$today_cell.$extra_classes.$mark_class.$passed."' ";
         $acal .= "<div id='day_" . $k . "' class='cal_cell " . $today_cell . $extra_classes . $mark_class . $passed . "' ";
         // new event link
         if ($knum >= $now['numeric']) {
             $acal .= "onclick='show_event_panel(" . $key_date[0] . "," . $key_date[1] . "," . $key_date[2] . ",\"\"," . $calendar['id'] . ")'";
         }
         // close, with or without onclick
         $acal .= ">";
         // date
         $acal .= "<span>" . $key_date[2] . "</span>";
         // close
         $acal .= "</div>";
         // close the month div
         if ($key_date[2] == days_in_month($key_date[1], $key_date[0])) {
             $acal .= "</div>";
         }
         // end of the year means close the month div and add to panels array
         if (in_array($md, array('03-31', '06-30', '09-30', '12-31')) or $k == $calendar['until_date']) {
             $acal .= "</div>";
             $acal .= "</div>";
         }
     }
     // set the admin colours on the days
     foreach ($es as $name => $details) {
         $acal .= "<script>";
         $acal .= "\$('.hl_" . $details['id'] . "').css({'background-color':'" . $colours[$details['details']['colour_choice']]['fill'] . "','border':'1px solid " . $colours[$details['details']['colour_choice']]['border'] . "','opacity':'0.75'});";
         $acal .= "</script>";
     }
     // a bit naughty, but this js moves the 'all previous' from the top to out of the way at the bottom
     $acal .= "<script>";
     $acal .= "\$('.all_previous_panel').appendTo(\$('.all_previous_panel').parent());";
     $acal .= "</script>";
     $event_list['calendar'] = $acal;
     $event_list['undo'] = $uf;
     return $event_list;
     /* BENCHMARK */
     $this->benchmark->mark('func_admin_calendar_end');
 }
Exemple #5
0
 private function log_sql($table, $id, $sql)
 {
     $date = date('Y-m-d');
     $time = date('H:i:s');
     $logFile = fopen(SERVER_BASE . 'logsql/' . $date . '.txt', 'a') or die('cannot open logsql file');
     fwrite($logFile, get_now() . ' table ' . $table . ' id ' . $id . ' ' . $sql . NL);
     fclose($logFile);
 }
 function update_database($data)
 {
     //printr($_SESSION,true);
     $TransactionId = $data['TransactionId'];
     $TransactionAmount = $data['TransactionAmount'];
     $subcription_type_id = $_SESSION['SubscriptionTypeId'];
     $PayPalCurrencyCode = $_SESSION['PayPalCurrencyCode'];
     $userId = $_SESSION['userId'];
     $currency_id = $this->service->get_currency_id($PayPalCurrencyCode);
     $details = $this->service->get_subscription_detail($subcription_type_id, $currency_id);
     $ip = get_client_ip();
     $ip_detail = get_ip_detail($ip);
     //$ip_detail =get_ip_detail("110.44.115.210");
     $country = '';
     $error = '';
     $success = false;
     $user_sub_id = '';
     if (!empty($ip_detail)) {
         $country = $this->global_model->get_country_id($ip_detail->country_code);
     } else {
         //$error .="Invalid IP address.";
     }
     if (empty($country)) {
         //$error .='Country Could not track. ';
     }
     if ($details && !empty($details)) {
         $this->db->trans_start();
         $active_status = ActiveRowStatus();
         $payment_method = $this->service->get_payment_method('Paypal');
         $insert_user_sub['UserId'] = $userId;
         $insert_user_sub['SubscriptionTypeId'] = $details->SubscriptionTypeId;
         $insert_user_sub['SubscriptionPriceId'] = $details->SubscriptionPriceId;
         $insert_user_sub['ValidTillDate'] = get_validity_date(get_now(), $details->ValidityPeriod);
         $insert_user_sub['MoviesCount'] = 0;
         $insert_user_sub['IsPaid'] = 1;
         $insert_user_sub['IPAddress'] = $ip;
         $insert_user_sub['CountryId'] = $country;
         $insert_user_sub['RowStatusId'] = $active_status;
         $insert_user_sub['LastUpdatedDate'] = get_now();
         $user_sub_id = $this->global_model->insert_data($this->TblUserSubscriptions, $insert_user_sub);
         if ($user_sub_id) {
             $insert_sub_payment['UserId'] = $userId;
             $insert_sub_payment['UserSubscriptionId'] = $user_sub_id;
             $insert_sub_payment['PaymentMethodId'] = $payment_method;
             $insert_sub_payment['CurrencyId'] = $currency_id;
             $insert_sub_payment['TransactionId'] = $TransactionId;
             $insert_sub_payment['TransactionAmount'] = $TransactionAmount;
             $insert_sub_payment['TransactionDate'] = get_now();
             $insert_sub_payment['RowStatusId'] = $active_status;
             $sud_payment_id = $this->global_model->insert_data($this->TblSubscriptionPayment, $insert_sub_payment);
         }
         $this->db->trans_complete();
         if ($this->db->trans_status() === FALSE) {
             $success = false;
             $error .= 'Error In Subscription.Try again later';
         } else {
             $success = true;
             $error .= '';
         }
     } else {
         $success = false;
         $error .= 'Subscription is not available';
     }
     $action['success'] = $success;
     $action['msg'] = $error;
     $action['user_subcription_id'] = $user_sub_id;
     return $action;
 }
Exemple #7
0
function insert_changes($the_db, $the_table_name, $the_table_id)
{
    $sql = 'SELECT id' . '  FROM Changes' . ' WHERE table_name ="' . $the_table_name . '"' . '   AND table_id =' . $the_table_id;
    $my_id = $the_db->fetchOne($sql);
    if ($my_id) {
        $sql = 'UPDATE Changes' . '   SET updated_at ="' . get_now() . '"' . ', servers = ""' . ' WHERE id =' . $my_id;
    } else {
        $sql = 'INSERT Changes' . '   SET updated_at ="' . get_now() . '"' . ', table_name ="' . $the_table_name . '"' . ', table_id =' . $the_table_id;
    }
    $the_db->query($sql);
}
Exemple #8
0
 public function calendar_save($post, $id)
 {
     /* BENCHMARK */
     $this->benchmark->mark('func_calendar_save_start');
     // only do the create stuff if it's a create !
     if (!is_numeric($post['id'])) {
         $this->load->model('events_admin_model');
         // generate a new calendar
         $this->load->helper('date_helper');
         $this->load->helper('date_convert_helper');
         // now, for the start of the calendar
         $now = get_now();
         // until date as a number
         $this->load->config('admin');
         if ($post['until_date'] != '' ? $until = str_replace("-", "", $post['until_date']) : ($until = $now['year'] + $this->config->item('years_ahead') . "1231")) {
         }
         // an array of cells
         $cells = array();
         // add cells
         $cells = $this->events_admin_model->add_cells($cells, $now['year'], $until);
         // make the hash value
         $hash = md5($id . time());
         // save that calendar as json into the calendar table
         $update_data = array('until_date' => $until, 'event_json' => json_encode($cells), 'validation_hash' => $hash);
         $this->db->where('node_id', $id);
         $this->db->update('calendar', $update_data);
     } else {
         $this->load->model('events_admin_model');
         // an update so we need to look at the until dates
         $calendar = $this->node_model->get_node($id, 'calendar');
         $cal_until = str_replace('-', '', $calendar['until_date']);
         $until = str_replace('-', '', $post['until_date']);
         if ($until > $cal_until) {
             // make start and end
             $start_year = substr($calendar['until_date'], 0, 4);
             // add some extra cells
             $cells = $this->events_admin_model->add_cells(json_decode($calendar['event_json'], true), $start_year, $until);
             // update new values
             $update_data = array('until_date' => $until, 'event_json' => json_encode($cells));
             $this->db->where('node_id', $id);
             $this->db->update('calendar', $update_data);
         }
     }
     /* BENCHMARK */
     $this->benchmark->mark('func_calendar_save_end');
 }
 public function node_details_data($panel, $data, $user, $node)
 {
     /* BENCHMARK */
     $this->benchmark->mark('func_node_details_data_start');
     // common to all nodes - things like tabs, images, inplace editing etc.
     // IMAGE - the main image for the node
     $img = $this->image_model->get_images($node['id'], 1);
     if (count($img)) {
         $data['main_image'] = "/user_img/" . $img[0]['user_id'] . "/" . $img[0]['image_filename'] . "s700" . $img[0]['image_ext'];
         $data['main_thumb'] = thumbnail_url($img[0], 360);
         $data['small_thumb'] = thumbnail_url($img[0], 120);
     }
     // IMAGES
     // all the images
     $data['images'] = $this->image_model->get_images($node['id'], 1);
     // a large image slider
     // INPLACE EDITING - set up the in place editing
     if (($user['user_type'] == 'super_admin' or $user['user_type'] == 'admin_user' or 1 == $data['owns_node']) && 0 == $data['admin_page']) {
         $data['javascript'] .= "<script type='text/javascript' src='/js/tinymce/tiny_mce.js'></script>";
         $data['admin_user'] = 1;
         $data['clean_html'] = quotes_to_entities(preg_replace('/\\s+/', ' ', addslashes($data['node_details']['node_html'])));
         $hidden_data = array('node_id' => $node['id']);
         $data['html_form_open'] = form_open($node['type'] . '/' . $node['id'] . '/inplace_save', '', $hidden_data);
     } else {
         $data['admin_user'] = 0;
         $data['clean_html'] = '';
         $data['html_form_open'] = '';
     }
     $data['details_text'] = '';
     $data['in_page'] = '';
     // where is it going ?
     if (1 == $node['show_in_details'] ? $ref = 'details_text' : ($ref = 'in_page')) {
     }
     // build the deatils text, in a form if needed
     $data[$ref] .= "<div id='" . $node['type'] . "_text' class='node_text'>";
     if (1 == $data['admin_user'] && 1 == $node['show_edit']) {
         $data[$ref] .= $data['html_form_open'];
         $data[$ref] .= "<div id='node_html_edit_button' class='submit' onclick='load_inplace(\"" . $data['clean_html'] . "\",\"" . $user['user_id'] . "\")'>click to edit</div>";
         $data[$ref] .= "<div id='" . $node['type'] . "_html_display' class='node_html_display'>";
         $data[$ref] .= "<div class='" > $node['type'] . "_html editable'>";
         $data[$ref] .= $data['node_details']['node_html'];
         $data[$ref] .= "</div>";
         $data[$ref] .= "</form>";
     } else {
         $data[$ref] .= "<div class='" . $node['type'] . "_html_display node_html_display'>";
         $data[$ref] .= $data['node_details']['node_html'];
         $data[$ref] .= "</div>";
     }
     $data[$ref] .= "</div>";
     // SCROLLERS - next and previous nodes in this set of nodes
     if (in_array($node['type'], $this->config->item('scroller_array'))) {
         $panel_suffix = '';
         if (isset($panel)) {
             if ($node['type'] != 'calendar' || $panel != 'details') {
                 $panel_suffix = "/" . $panel;
             } else {
                 if (strlen($data['url_extra'])) {
                     $panel_suffix = "/" . $data['url_extra'];
                 }
             }
         }
         if ($this->session->userdata('search_term')) {
             $this->load->model('search_model');
             $nodes = $this->search_model->search($this->session->userdata('search_term'), $this->config->item('search_nodes'));
             $next_prev_text = 'search result';
         } else {
             $nodes = $this->node_model->get_nodes(array('type' => $node['type'], 'visible' => 1));
             $next_prev_text = $node['human_type'];
         }
         $scroll_intro_text = "scroll through " . $next_prev_text . "s:";
         $nc = count($nodes);
         for ($x = 0; $x < $nc; $x++) {
             if ($nodes[$x]['url'] == $node['url']) {
                 if (0 == $x) {
                     $pl = "<span class='left_scr_deact scr_deact sprite'>previous " . $next_prev_text . "</span>";
                     $pl .= "<span class='scr_divider'>|</span>";
                     if (1 == $nc) {
                         $nl = "<span class='right_scr_deact scr_deact sprite'>next " . $next_prev_text . "</span>";
                     } else {
                         $nl = "<a href='/" . $nodes[$x + 1]['url'] . $panel_suffix . "' title='next " . $next_prev_text . ": " . str_replace("'", '', $nodes[$x + 1]['name']) . "'><span class='right_scr scr sprite'>next " . $next_prev_text . "</span></a>";
                     }
                 } elseif ($x == $nc - 1) {
                     $pl = "<a href='/" . $nodes[$x - 1]['url'] . $panel_suffix . "' title='previous " . $next_prev_text . ": " . str_replace("'", '', $nodes[$x - 1]['name']) . "'><span class='left_scr scr sprite'>previous " . $next_prev_text . "</span></a>";
                     $pl .= "<span class='scr_divider'>|</span>";
                     $nl = "<span class='right_scr_deact scr_deact sprite'>next " . $next_prev_text . "</span>";
                 } else {
                     $pl = "<a href='/" . $nodes[$x - 1]['url'] . $panel_suffix . "' title='previous " . $next_prev_text . ": " . str_replace("'", '', $nodes[$x - 1]['name']) . "'><span class='left_scr scr sprite'>previous " . $next_prev_text . "</span></a>";
                     $pl .= "<span class='scr_divider'>|</span>";
                     $nl = "<a href='/" . $nodes[$x + 1]['url'] . $panel_suffix . "' title='next " . $next_prev_text . ": " . str_replace("'", '', $nodes[$x + 1]['name']) . "'><span class='right_scr scr sprite'>next " . $next_prev_text . "</span></a>";
                 }
             }
         }
     }
     // set the html snippet
     $scr = '';
     if (0 == $data['admin_page']) {
         if (isset($pl) && isset($nl)) {
             $scr .= "<div id='scrollers'>";
             $scr .= "<span id='scroll_intro'>" . $scroll_intro_text . "</span>";
             $scr .= "<div id='scroll_buttons'>";
             $scr .= $pl;
             $scr .= $nl;
             $scr .= "</div>";
             $scr .= "</div>";
         }
     }
     $data['scrollers'] = $scr;
     // SOCIAL - includes share this stuff etc.
     $sb = '';
     if (1 == $node['social']) {
         // !!!!!
         // NB needs to be in a model so it can be used on lists
         // get the sites to share to from this node
         $sites = $this->config->item('social_sites');
         // open social_buttons
         $sb .= "<div id='share_buttons'>";
         // iterate - we can add extra ones in here as and when
         foreach ($sites as $site => $config) {
             switch ($site) {
                 case 'facebook':
                     $sb .= $this->share_model->facebook_like($config, $node, $data);
                     break;
                 case 'twitter':
                     $sb .= $this->share_model->tweet_button($config, $node, $data);
                     break;
             }
         }
         // close social_buttons
         $sb .= "</div>";
     }
     $data['share_buttons'] = $sb;
     // TABS - tab menus, different for each type of node, not if admin
     $data['tabs'] = array();
     $data['count_unread'] = '';
     if (1 == $node['show_tabs']) {
         $tabs_config = $this->config->item('tabs');
         if (is_array($tabs_config)) {
             // first look for type based tabs
             $data['tabs'] = $tabs_config[$node['type']];
         } else {
             // old sites, only ever used details
             $data['tabs'][] = 'details';
         }
     }
     // TAB - specific data for each tab type
     $actions = array();
     $articles = array();
     $comments = array();
     $comment_form = '';
     $conversations = array();
     $images = array();
     $messages = array();
     $message_form = '';
     $stream = array();
     switch ($panel) {
         case 'articles':
         case 'blog':
             $articles = $this->node_model->get_nodes(array('type' => 'article', 'user_id' => $node['id'], 'visible' => 1), 1);
             break;
         case 'calendar':
             $calendar = array();
             $calendars = $this->node_model->get_nodes(array('type' => 'calendar', 'user_id' => $node['id']));
             if (count($calendars) > 0) {
                 $this->load->model('events_model');
                 $calendar = $this->node_model->get_node($calendars[0]['id'], 'calendar');
                 $calendar = $this->events_model->get_calendar($calendar, $node['url'] . "/calendar", $data['params']);
             }
             $data['calendar'] = $calendar;
         case 'comments':
         case 'details':
         case 'intro':
             $this->load->model('comment_model');
             $comments = $this->comment_model->get_comments($node);
             $comment_form = $this->comment_model->comment_form($node);
             $data['javascript'] .= "<script src='/js/comments.js'></script>";
             $data['javascript'] .= "<script type='text/javascript' src='/js/tinymce/tiny_mce.js'></script>";
         case 'images':
         case 'gallery':
             $images = $this->image_model->get_images($node['id']);
             break;
         case 'messages':
             if (isset($this->user['user_id'])) {
                 $this->load->model('conversation_model');
                 $this->load->model('message_model');
                 if ($node['id'] == $user['id']) {
                     // get the conversations
                     $conversations = $this->conversation_model->get_users_conversations($user);
                     if (count($conversations) > 0) {
                         $conversation = $conversations[0];
                         $messages = $this->message_model->get_conversation_messages($user, $conversation);
                     }
                     // form if we have a conversation
                     if (isset($conversation) && count($conversation) > 0) {
                         $message_form = $this->message_model->message_form($conversation);
                     }
                 } else {
                     // just get the messages between the user and the node
                     $conversation = $this->conversation_model->get_conversation($user, $node);
                     // form anyway, to start a conversation
                     if (!is_array($conversation)) {
                         $conversation = array('conversation_id' => 0);
                     }
                     if (count($conversation) > 0) {
                         $messages = $this->message_model->get_conversation_messages($user, $conversation);
                     }
                     $message_form = $this->message_model->message_form($conversation, $node);
                 }
                 $data['javascript'] .= "<script src='/js/messages.js'></script>";
                 $data['javascript'] .= "<script type='text/javascript' src='/js/tinymce/tiny_mce.js'></script>";
             }
             break;
         case 'stream':
         case 'activity':
             // stream model is also used below to merge streams for users
             $this->load->model('stream_output_model');
             $stream = $this->stream_output_model->get_actions($node);
             $this->load->config('action');
             $actions = $this->config->item('stream_actions');
             break;
     }
     $data['actions'] = $actions;
     $data['articles'] = $articles;
     $data['comments'] = $comments;
     $data['comment_form'] = $comment_form;
     $data['conversations'] = $conversations;
     $data['images'] = $images;
     $data['messages'] = $messages;
     $data['message_form'] = $message_form;
     $data['stream'] = $stream;
     // TAB HTML
     $ntb = '';
     // only if there are tabs (and they are shown as this array will be empty if not)
     if (count($data['tabs']) > 0) {
         // open the list
         $ntb .= "<div id='node_tabs'>";
         $ntb .= "<ul>";
         // iterate over the tabs set above
         for ($x = 0; $x < count($data['tabs']); $x++) {
             // class for selected
             if ($data['current_tab'] == $data['tabs'][$x] ? $class = 'tab_sel' : ($class = 'tab')) {
             }
             // message count for the message tab
             if ('messages' == $data['tabs'][$x]) {
                 $this->load->model('message_model');
                 $count_unread = $this->message_model->count_unread($user);
                 $suffix = '';
                 if (isset($count_unread['unread'])) {
                     $suffix = " [" . $count_unread['unread'] . "]";
                 }
                 $tab_text = $data['tabs'][$x] . $suffix;
             } else {
                 $tab_text = $data['tabs'][$x];
             }
             // the tab itself
             $ntb .= "<li>";
             $ntb .= "<a href='/" . $data['node']['url'] . "/" . $data['tabs'][$x] . "'>";
             $ntb .= "<span class='" . $class . "'>";
             $ntb .= $tab_text;
             $ntb .= "</span>";
             $ntb .= "</a>";
             $ntb .= "</li>";
         }
         // close the list
         $ntb .= "</ul>";
         $ntb .= "</div>";
     }
     $data['node_tabs'] = $ntb;
     // VOTE BUTTONS
     $data['vote_buttons'] = '';
     if (isset($user['id']) && is_numeric($user['id'])) {
         $this->load->model('voting_model');
         $data['vote_buttons'] = "<div class='vote_buttons votes" . $node['id'] . "'>" . $this->voting_model->get_vote_buttons($user, $node) . "</div>";
     }
     // specific to node type, such as add to basket, variations and user connection stuff
     // CALENDAR
     if (!isset($calendar)) {
         $calendar = '';
     }
     if ('calendar' == $node['type']) {
         $this->load->model('events_model');
         $calendar = $this->events_model->get_calendar($node, $node['url'], $data['url_extra']);
     }
     if (isset($node['calendar_id']) && $node['calendar_id'] > 0) {
         $this->load->model('events_model');
         $calendar = $this->events_model->get_calendar($this->node_model->get_node($node['calendar_id'], 'calendar'), $node['url'] . "/calendar", $data['params']);
     }
     $data['calendar'] = $calendar;
     // EVENT (OR ANY EVENTS ARE FOUND WITH THIS AS A CATEGORY ID)
     $query = $this->db->select('*')->from('node')->where("type = 'event' and (id = " . $node['id'] . " or category_id = " . $node['id'] . ")");
     $res = $query->get();
     $events = $res->result_array();
     $el = array('past' => array(), 'upcoming' => array());
     if (count($events) > 0) {
         $now = time();
         $events_by_id = $this->node_model->nodes_by_id($events);
         // get all the ids into an array
         $nids = array();
         foreach ($events as $e) {
             $nids[] = $e['id'];
         }
         // get all the event instances from the nvar table, ordered by time stamp
         $seq = array();
         if (count($nids)) {
             $query = $this->db->select('*')->from('nvar')->where_in('node_id', $nids)->order_by('event_timestamp');
             $res = $query->get();
             $seq = $res->result_array();
         }
         // iterate over all the event instances
         foreach ($seq as $e) {
             // place into the correct array
             if ($now > $e['event_timestamp'] ? $akey = 'past' : ($akey = 'upcoming')) {
             }
             // get the event for this iteration
             $event = $events_by_id[$e['node_id']];
             // convert the timestamp
             $dt = get_now($e['event_timestamp']);
             // if this is node is a category into which events falls
             if (count($events) > 1) {
                 // just the sequence details, rest on the page
                 $edet = $e['event_timestamp'];
             } else {
                 // output heading with link to event, use event query data
                 $edet = $event['name'] . '-' . $e['event_timestamp'];
             }
             // add to array - include the event and sequence details in case we want to use that in
             // project data model to build something more complex than a basic html output
             $el[$akey][] = array('html' => $edet, 'e' => array_merge($event, $e));
         }
         // reverse the past events so that the list starts with the most recent past event
         $el['past'] = array_reverse($el['past']);
     }
     $data['event_list'] = $el;
     // PRODUCT
     // add to basket button
     $data['add_to_basket'] = '';
     // add this product to basket panel
     $add_quantity = "<div id='add_quantity_field'><input id='add_quantity' class='form_field' type='text' name='add_quantity' value='1' onkeyup='check_quantity()' tabindex='11'/></div>";
     // only if product
     if ('product' == $node['type']) {
         $this->load->model('variation_model');
         $variations = json_decode($data['node_details']['nvar_json'], true);
         $c = 0;
         foreach ($variations as $v) {
             // select the first variation as default
             if (0 == $c) {
                 $data['main_variation'] = $this->variation_model->format_add_panel($v);
                 $selected = $v['nvar_id'];
             }
             // if we hit a main variation then update the variation
             if (1 == $v['main']) {
                 $data['main_variation'] = $this->variation_model->format_add_panel($v);
                 if (isset($data['selected']) ? $selected = $data['selected'] : ($selected = $v['nvar_id'])) {
                 }
                 break;
             }
             $c++;
         }
         $data['variation_selector'] = $this->variation_model->variation_selector($data['node_details'], $selected);
         $atb = '';
         // open add to basket panel
         $atb .= "<div id='add_basket_panel'>";
         // add panel text
         $atb .= "<div id='add_panel_text'>";
         $atb .= $data['main_variation'];
         $atb .= "</div>";
         // add panel - updated by js
         $atb .= "<div id='add_panel'>";
         $atb .= form_open('/basket/add');
         $atb .= "<input type='hidden' name='product_add' value=''/>";
         $atb .= $data['variation_selector'];
         $atb .= $add_quantity;
         $atb .= "<input id='add_submit' class='submit checkout' type='submit' name='submit' value='add to basket'/>";
         // no closing div for add_panel, its somewhere in the variation selector or :-\ must fix this !!
         $atb .= "</form>";
         // script builds button
         $atb .= '<script type="text/javascript">';
         $atb .= 'if (window.focus)';
         $atb .= '{';
         $atb .= 'var add_span="<div id=\'variation_selector_field\' class=\'check_this\'>' . $data['variation_selector'] . '</div>";';
         $atb .= 'add_span+="<span id=\'add_button\' class=\'submit checkout\' onclick=\'basket_add()\' tabindex=\'12\'>add to basket</span>";';
         $atb .= 'add_span+="' . $add_quantity . '<span id=\'not_enough_stock\'></span>";';
         $atb .= '$("#add_panel").html(add_span);';
         $atb .= '}';
         $atb .= '</script>';
         // close add to basket panel
         $atb .= "</div>";
         $data['add_to_basket'] = $atb;
     }
     // USER AND GROUP
     $data['connection_buttons'] = array();
     $followable = $this->config->item('followable');
     if ('user' == $node['type'] or 'groupnode' == $node['type'] or is_array($followable) && in_array($node['type'], $followable)) {
         $this->load->model('connection_model');
         $this->load->model('connection_button_model');
         // user and group connections - users have more connection types
         $data['connections'] = $this->connection_model->get_connections($node);
         // connection buttons
         if (isset($this->user['user_id'])) {
             $data['connection_buttons'] = $this->connection_button_model->connection_buttons($user, $node);
         }
     }
     // friends stream data
     if ('user' == $node['type'] && in_array($panel, array('stream', 'activity'))) {
     }
     return $data;
     /* BENCHMARK */
     $this->benchmark->mark('func_node_details_data_end');
 }
Exemple #10
0
function dump_pcap($fname, $force = false)
{
    $hdr = null;
    $path_parts = pathinfo($fname);
    $dir = preg_replace('#.pcap$#i', '', $path_parts['basename']);
    if (!is_dir('./' . $dir)) {
        mkdir('./' . $dir);
    }
    $ret = '';
    $fs = filesize($fname);
    if (file_exists($dir . '/' . $fs . ".htm") && !$force) {
        $ret = "Previously parsed<br/>" . file_get_contents($dir . '/' . $fs . ".htm");
        return $ret;
    }
    clean_dir($dir);
    $ret = $fname . "<br/>" . get_now() . "<br/><br/>";
    if (valid_pcap($fname)) {
        $cnt = 0;
        $hdr = new pcap_hdr_s();
        $hdr->records = array();
        $hdr->size = $fs;
        $b = file_get_contents($fname, NULL, NULL, 0, 24);
        $lng = byte_array_to_long($b, 0);
        $hdr->magic_number = $lng;
        $hdr->version_major = byte_array_to_int($b, 4);
        $hdr->version_minor = byte_array_to_int($b, 6);
        $hdr->thiszone = byte_array_to_long($b, 8);
        $hdr->sigfigs = byte_array_to_long($b, 12);
        $hdr->snaplen = byte_array_to_long($b, 16);
        $hdr->network = byte_array_to_long($b, 20);
        $offset = 24;
        if ($hdr->network == 1) {
            // link type was expected. continue
            while ($offset + 54 < $hdr->size) {
                $off = $offset;
                $cnt++;
                $pr = new pcap_record();
                $b = file_get_contents($fname, NULL, NULL, $offset, 16);
                $pr->ts_sec = byte_array_to_long($b, 0);
                $pr->ts_usec = byte_array_to_long($b, 4);
                $pr->incl_len = byte_array_to_long($b, 8);
                $pr->orig_len = byte_array_to_long($b, 12);
                $off += 16;
                if ($pr->incl_len < 0 || $pr->orig_len < 0) {
                    $ret .= "Error parsing";
                    break;
                } else {
                    // ethernet header
                    $pr->eth = parse_ethernet_header($fname, $off);
                    $off += 14;
                    // add size of ethernet packet header
                    // ip header
                    $pr->ip = parse_ip($fname, $off);
                    $off += $pr->ip->hdr_len * 4;
                    // add size of ip packet header
                    if ($pr->ip->proto == 6) {
                        // tcp
                        $pr->tcp = parse_tcp($fname, $off, $pr->ip->src, $pr->ip->dest, $pr->incl_len - (14 + $pr->ip->hdr_len * 4));
                        $off += $pr->tcp->data_offset * 4;
                        // add size of tcp packet header
                        // data
                        $dend = $pr->incl_len - (14 + $pr->ip->hdr_len * 4 + $pr->tcp->data_offset * 4);
                        if ($dend > 0) {
                            $pr->tcp->data = file_get_contents($fname, NULL, NULL, $off, $dend);
                            if ($pr->tcp->data != "") {
                                $fn = $pr->ip->src_ip . "-" . $pr->tcp->src_port;
                                $fn .= "--" . $pr->ip->dest_ip . "-" . $pr->tcp->dest_port;
                                $fn .= "--" . $pr->tcp->ack;
                                $seq = 0;
                                if (file_exists($dir . '/' . $fn . ".seq")) {
                                    $seq = file_get_contents($dir . '/' . $fn . ".seq");
                                }
                                //$se = chr(($pr->tcp->seq >> 24) & 0xff) . chr(($pr->tcp->seq >> 16) & 0xff) . chr(($pr->tcp->seq >> 8) & 0xff) . chr($pr->tcp->seq & 0xff);
                                if ($pr->tcp->seq > $seq) {
                                    // is packet unique?
                                    file_put_contents($dir . '/' . $fn . ".seq", $pr->tcp->seq);
                                    file_put_contents($dir . '/' . $fn . ".raw", $pr->tcp->data, FILE_APPEND);
                                }
                            }
                        }
                    } elseif ($pr->ip->proto == 17) {
                        // udp
                    } elseif ($pr->ip->proto == 1) {
                        // icmp
                    }
                }
                $pr->index = $cnt;
                $offset += $pr->incl_len + 16;
            }
        } else {
            $ret .= "Unknown network link type<br/>";
        }
    } else {
        $ret .= "Invalid pcap file<br/>";
    }
    $ret .= parse_streams($fname);
    file_put_contents($dir . '/' . $fs . ".htm", $ret);
    return $ret;
}