function create_position($screen_id_in, $feed_id_in, $field_id_in, $weight_in = DEFAULT_WEIGHT){
		if($this->set){
			return true; //You've already got an object!
		} else {
		  if(!is_numeric($screen_id_in) || !is_numeric($feed_id_in) || !is_numeric($field_id_in) || !is_numeric($weight_in)){
		    return false;
		  }
			$sql = "SELECT COUNT(id) FROM position WHERE screen_id = $screen_id_in AND feed_id = $feed_id_in AND field_id = $field_id_in";
			$res = sql_query($sql);
			$data = (sql_row_keyed($res,0));
			if( $data['COUNT(id)'] != 0){
				return false;  //Implying the mapping already exists
			} else {
				$sql = "INSERT INTO position (screen_id, feed_id, field_id, weight) VALUES ($screen_id_in, $feed_id_in, $field_id_in, $weight_in)";
				$res = sql_query($sql);
				if($res){
					$this->id = sql_insert_id();
					$this->screen_id = $screen_id_in;
					$this->feed_id = $feed_id_in;
					$this->field_id = $field_id_in;
					$this->weight = $weight_in;
				
					$this->set = true;
					return true;
				} else {
					return false;
				}
			}
        }
	
	}
 function feedAction()
 {
     $this->feed = new Feed($this->args[1]);
     if (!$this->feed->user_priv($_SESSION['user'], 'moderate')) {
         $this->flash('You do not have enough privileges to moderate this feed', 'error');
         redirect_to(ADMIN_URL . "/moderate");
     }
     $sql = "SELECT content.id FROM content\n                LEFT JOIN feed_content\n                ON content.id = feed_content.content_id\n                WHERE feed_content.feed_id = {$this->feed->id}\n                AND feed_content.moderation_flag IS NULL\n                GROUP BY content.id\n                ORDER BY content.type_id, content.name;";
     $res = sql_query($sql);
     for ($i = 0; $row = sql_row_keyed($res, $i); ++$i) {
         $this->contents[] = new Content($row['id']);
     }
     $this->setTitle('Moderating ' . $this->feed->name);
     $this->breadcrumb($this->feed->name);
 }
 function listAction()
 {
     $ids = sql_select('group', 'id');
     $this->groups = array();
     if (is_array($ids)) {
         foreach ($ids as $group) {
             $group = new Group($group['id']);
             $this->groups[$group->id]['name'] = $group->name;
             $members = $group->get_members();
             $this->groups[$group->id]['members'] = is_array($members) ? count($members) : 0;
             $feeds_res = sql_query('SELECT COUNT(id) as feeds FROM `feed` WHERE `group_id` = ' . $group->id);
             $this->groups[$group->id]['controls'] = NULL;
             if ($feeds_res) {
                 $num_feeds = sql_row_keyed($feeds_res, 0);
                 $num_feeds = $num_feeds['feeds'];
                 if ($num_feeds == 1) {
                     $this->groups[$group->id]['controls'][] = "1 feed";
                 } else {
                     if ($num_feeds > 1) {
                         $this->groups[$group->id]['controls'][] = $num_feeds . " feeds";
                     }
                 }
             }
             $screens_res = sql_query('SELECT COUNT(id) as screens FROM `screen` WHERE `group_id` = ' . $group->id);
             if ($screens_res) {
                 $num_screens = sql_row_keyed($screens_res, 0);
                 $num_screens = $num_screens['screens'];
                 if ($num_screens == 1) {
                     $this->groups[$group->id]['controls'][] = "1 screen";
                 } else {
                     if ($num_screens > 1) {
                         $this->groups[$group->id]['controls'][] = $num_screens . " screens";
                     }
                 }
             }
         }
     }
 }
Esempio n. 4
0
function create_field_entry_rooms($disabled = FALSE)
{
    global $multiroom_allowed, $room_id, $area_id, $selected_rooms, $areas;
    global $tbl_room, $tbl_area;
    // $selected_rooms will be populated if we've come from a drag selection
    if (empty($selected_rooms)) {
        $selected_rooms = array($room_id);
    }
    // Get the details of all the enabled rooms
    $all_rooms = array();
    $sql = "SELECT R.id, R.room_name, R.area_id\n            FROM {$tbl_room} R, {$tbl_area} A\n           WHERE R.area_id = A.id\n             AND R.disabled=0\n             AND A.disabled=0\n        ORDER BY R.area_id, R.sort_key";
    $res = sql_query($sql);
    if ($res === FALSE) {
        trigger_error(sql_error(), E_USER_WARNING);
        fatal_error(FALSE, get_vocab("fatal_db_error"));
    }
    for ($i = 0; $row = sql_row_keyed($res, $i); $i++) {
        $all_rooms[$row['area_id']][$row['id']] = $row['room_name'];
    }
    echo "<div id=\"div_rooms\">\n";
    echo "<label for=\"rooms\">" . get_vocab("rooms") . ":</label>\n";
    echo "<div class=\"group\">\n";
    // First of all generate the rooms for this area
    $params = array('name' => 'rooms[]', 'id' => 'rooms', 'options' => $all_rooms[$area_id], 'force_assoc' => TRUE, 'value' => $selected_rooms, 'multiple' => $multiroom_allowed, 'mandatory' => $multiroom_allowed, 'disabled' => $disabled, 'attributes' => array('size="5"'));
    generate_select($params);
    // Then generate templates for all the rooms
    $params['disabled'] = TRUE;
    $params['create_hidden'] = FALSE;
    foreach ($all_rooms as $a => $rooms) {
        $attributes = array();
        $attributes[] = 'style="display: none"';
        // Put in some data about the area for use by the JavaScript
        $attributes[] = 'data-enable_periods=' . ($areas[$a]['enable_periods'] ? 1 : 0);
        $attributes[] = 'data-default_duration=' . (isset($areas[$a]['default_duration']) && $areas[$a]['default_duration'] != 0 ? $areas[$a]['default_duration'] : SECONDS_PER_HOUR);
        $attributes[] = 'data-default_duration_all_day=' . ($areas[$a]['default_duration_all_day'] ? 1 : 0);
        $attributes[] = 'data-max_duration_enabled=' . ($areas[$a]['max_duration_enabled'] ? 1 : 0);
        $attributes[] = 'data-max_duration_secs=' . $areas[$a]['max_duration_secs'];
        $attributes[] = 'data-max_duration_periods=' . $areas[$a]['max_duration_periods'];
        $attributes[] = 'data-max_duration_qty=' . $areas[$a]['max_duration_qty'];
        $attributes[] = 'data-max_duration_units="' . htmlspecialchars($areas[$a]['max_duration_units']) . '"';
        $attributes[] = 'data-timezone="' . htmlspecialchars($areas[$a]['timezone']) . '"';
        $room_ids = array_keys($rooms);
        $params['id'] = 'rooms' . $a;
        $params['options'] = $rooms;
        $params['value'] = $room_ids[0];
        $params['attributes'] = $attributes;
        generate_select($params);
    }
    // No point telling them how to select multiple rooms if the input
    // is disabled
    if ($multiroom_allowed && !$disabled) {
        echo "<span>" . get_vocab("ctrl_click") . "</span>\n";
    }
    echo "</div>\n";
    echo "</div>\n";
}
Esempio n. 5
0
 echo "</thead>\n";
 // TABLE BODY LISTING BOOKINGS
 echo "<tbody>\n";
 // This is the main bit of the display
 // We loop through time and then the rooms we just got
 // if the today is a day which includes a DST change then use
 // the day after to generate timesteps through the day as this
 // will ensure a constant time step
 // URL for highlighting a time. Don't use REQUEST_URI or you will get
 // the timetohighlight parameter duplicated each time you click.
 $hilite_url = "day.php?year={$year}&amp;month={$month}&amp;day={$day}&amp;area={$area}{$room_param}&amp;timetohighlight";
 $row_class = "even_row";
 // We can display the table in two ways
 if ($times_along_top) {
     // with times along the top and rooms down the side
     for ($i = 0; $row = sql_row_keyed($res, $i); $i++, $row_class = $row_class == "even_row" ? "odd_row" : "even_row") {
         echo "<tr>\n";
         $room_id = $row['id'];
         $room_cell_link = "week.php?year={$year}&amp;month={$month}&amp;day={$day}&amp;area={$area}&amp;room={$room_id}";
         draw_room_cell($row, $room_cell_link);
         for ($t = mktime($morningstarts, $morningstarts_minutes, 0, $month, $day + $j, $year); $t <= mktime($eveningends, $eveningends_minutes, 0, $month, $day + $j, $year); $t += $resolution) {
             // convert timestamps to HHMM format without leading zeros
             $time_t = date($format, $t);
             // and get a stripped version of the time for use with periods
             $time_t_stripped = preg_replace("/^0/", "", $time_t);
             // calculate hour and minute (needed for links)
             $hour = date("H", $t);
             $minute = date("i", $t);
             // set up the query strings to be used for the link in the cell
             $query_strings = array();
             $query_strings['new_periods'] = "area={$area}&amp;room={$room_id}&amp;period={$time_t_stripped}&amp;year={$year}&amp;month={$month}&amp;day={$day}";
Esempio n. 6
0
            echo "<p class=\"report_entries\"><span id=\"n_entries\">" . $nmatch . "</span> " . ($nmatch == 1 ? get_vocab("entry_found") : get_vocab("entries_found")) . "</p>\n";
        }
        // Report
        if ($output == REPORT) {
            open_report();
            report_header();
            $body_rows = array();
            for ($i = 0; $row = sql_row_keyed($res, $i); $i++) {
                report_row($body_rows, $row);
            }
            output_body_rows($body_rows, $output_format);
            close_report();
        } else {
            open_summary();
            if ($nmatch > 0) {
                for ($i = 0; $row = sql_row_keyed($res, $i); $i++) {
                    accumulate($row, $count, $hours, $report_start, $report_end, $room_hash, $name_hash);
                }
                do_summary($count, $hours, $room_hash, $name_hash);
            } else {
                // Excel doesn't seem to like an empty file with just a BOM, so give
                // it an empty row as well to keep it happy
                $values = array();
                output_row($values, $output_format);
            }
            close_summary();
        }
    }
}
if ($cli_mode) {
    exit(0);
 function content_details()
 {
     if ($this->content_id) {
         $content_id = $this->content_id;
         $sql = "SELECT c.id, c.content, c.mime_type, fc.duration FROM content c\n                        LEFT JOIN feed_content fc ON c.id = fc.content_id WHERE c.id = {$content_id} AND moderation_flag = 1;";
         $res = sql_query($sql);
         if ($res && sql_count($res)) {
             $data = sql_row_keyed($res, 0);
             $this->content_id = $data['id'];
             $json['content'] = stripslashes($data['content']);
             $json['mime_type'] = stripslashes($data['mime_type']);
             $json['duration'] = $data['duration'];
             if ($data['mime_type'] == 'text/time') {
                 //This executes time code
                 $json['mime_type'] = 'text/html';
                 $json['content'] = date($data['content']);
             }
             $this->log_back();
             return $json;
         } else {
             $this->construct_timeline();
             $this->get_content();
             return $this->content_details();
         }
     } else {
         $this->construct_timeline();
         $this->get_content();
         return $this->content_details();
     }
 }
	function avail_feeds(){
		if($this->screen_set){
			$sql = "SELECT id FROM feed WHERE id NOT IN (SELECT feed_id FROM position WHERE field_id = '$this->id' AND screen_id = '$this->screen_id') ORDER BY id ASC";
			$res = sql_query($sql);
			$i = 0;
			while($feed_row = sql_row_keyed($res, $i)){
				//$data[$i] = new Feed($feed_row['id']);
				$feeds[$i] = $feed_row['id'];
				$i++;
			}
			$obj = new Feed();
			$access = $obj->priv_get(new Screen($this->screen_id), 'subscribe');
			foreach($access as $feed){
				$allowed[] = $feed->id;
			}
			$intersect = array_intersect($allowed, $feeds);
			foreach($intersect as $feed_id){
				$data[] = new Feed($feed_id);
			}
			return $data;
		} else {
			return false;  //No screen = no fun!  Get it through your head!
		}
	}
Esempio n. 9
0
    if (!getAuthorised(1)) {
        showAccessDenied($day, $month, $year, $area, "");
        exit;
    }
} else {
    $initial_user_creation = 1;
    $user = "******";
    $level = 2;
}
/*---------------------------------------------------------------------------*\
|             Edit a given entry - 1st phase: Get the user input.             |
\*---------------------------------------------------------------------------*/
if (isset($Action) && ($Action == "Edit" or $Action == "Add")) {
    if ($Id >= 0) {
        $result = sql_query("select * from {$tbl_users} where id={$Id}");
        $data = sql_row_keyed($result, 0);
        sql_free($result);
    }
    if ($Id == -1 || !$data) {
        foreach ($fields as $fieldname) {
            $data[$fieldname] = "";
        }
    }
    /* First make sure the user is authorized */
    if (!getWritable($data['name'], $user)) {
        showAccessDenied(0, 0, 0, "", "");
        exit;
    }
    print_header(0, 0, 0, 0, "");
    print "<div id=\"form_container\">";
    print "<form id=\"form_edit_users\" method=\"post\" action=\"" . htmlspecialchars(basename($PHP_SELF)) . "\">\n";
Esempio n. 10
0
function system_info()
{
    header("Content-type: text/xml");
    echo '<?xml version="1.0"?>';
    $sql = "SELECT id, name FROM feed WHERE type != 3";
    $res = sql_query($sql);
    $i = 0;
    ?>

<systeminfo>
  <feeds>
<?php 
    while ($row = sql_row_keyed($res, $i)) {
        ?>
    <feed>
        <id><?php 
        echo $row['id'];
        ?>
</id>
        <name><?php 
        echo htmlspecialchars($row['name']);
        ?>
</name>
    </feed>
<?php 
        $i++;
    }
    ?>
  </feeds>
<?php 
    $sql = "SELECT name FROM type";
    $res = sql_query($sql);
    $i = 0;
    ?>
  <types>
<?php 
    while ($row = sql_row_keyed($res, $i)) {
        ?>
    <type><?php 
        echo htmlspecialchars($row['name']);
        ?>
</type>
<?php 
        $i++;
    }
    ?>
  </types>
</systeminfo>
<?php 
}
  function get_for_user($user_id, $hidden = 0, $since= '', $offset=0,$count = 5){
    if(!is_numeric($user_id) || !is_numeric($offset) || !is_numeric($count)){
      return false;
    }
    $hide_string = '';
    if($hidden !== ''){
      if(is_numeric($hidden)){
        $hide_string = ' AND `hidden` = ' . $hidden;
      } else {
        return false;
      }
    }

    $ts_string = '';
    if($since != ''){
      if($timestamp = strtotime($since)){
        $ts_string = " AND `timestamp` > '" . date("Y-m-d G:i:s", $timestamp) . "' ";
      } else {
        return false;
      }
    }
    
    $sql = 'SELECT newsfeed.id FROM newsfeed LEFT JOIN notifications ON newsfeed.notification_id = notifications.id WHERE user_id = ' . $user_id . $hide_string . $ts_string . ' ORDER BY notifications.timestamp  DESC LIMIT ' . $offset . ' , ' . $count;
    
    $res = sql_query($sql);
    $notifs = array();
    if($res != 0){
      $i = 0;
      while($row = sql_row_keyed($res, $i)){
        $notifs[] = new Newsfeed($row['id']);
        $i++;
      }
    }
    return $notifs;
  }
Esempio n. 12
0
/**
 * Gather all fields values for an entry. Used for emails to get previous
 * entry state.
 *
 * @param int     $id       entry id to get data
 * @param int     $series   1 if this is a serie or 0
 * @return bool             TRUE or PEAR error object if fails
 */
function getPreviousEntryData($id, $series)
{
    global $tbl_area, $tbl_entry, $tbl_repeat, $tbl_room, $enable_periods;
    //
    $sql = "\n    SELECT  e.name,\n            e.description,\n            e.create_by,\n            r.room_name,\n            a.area_name,\n            e.type,\n            e.room_id,\n            e.repeat_id,\n            e.timestamp,\n            (e.end_time - e.start_time) AS tbl_e_duration,\n            e.start_time AS tbl_e_start_time,\n            e.end_time AS tbl_e_end_time,\n            a.area_admin_email,\n            r.room_admin_email";
    // Here we could just use $tbl_repeat.start_time, and not use alias,
    // as the last column will take precedence using mysql_fetch_array,
    // but for portability purpose I will not use it.
    if (1 == $series) {
        $sql .= ", re.rep_type, re.rep_opt, re.rep_num_weeks,\n            (re.end_time - re.start_time) AS tbl_r_duration,\n            re.start_time AS tbl_r_start_time,\n            re.end_time AS tbl_r_end_time,\n            re.end_date AS tbl_r_end_date";
    }
    $sql .= "\n    FROM {$tbl_entry} e, {$tbl_room} r, {$tbl_area} a ";
    1 == $series ? $sql .= ', ' . $tbl_repeat . ' re ' : '';
    $sql .= "\n    WHERE e.room_id = r.id\n    AND r.area_id = a.id\n    AND e.id={$id}";
    1 == $series ? $sql .= " AND e.repeat_id = re.id" : '';
    //
    $res = sql_query($sql);
    !$res ? fatal_error(0, sql_error()) : '';
    sql_count($res) < 1 ? fatal_error(0, get_string('invalid_entry_id', 'block_mrbs')) : '';
    $row = sql_row_keyed($res, 0);
    sql_free($res);
    // Store all needed values in $mail_previous array to pass to
    // notifyAdminOnDelete function (shorter than individual variables -:) )
    $mail_previous['namebooker'] = $row['name'];
    $mail_previous['description'] = $row['description'];
    $mail_previous['createdby'] = $row['create_by'];
    $mail_previous['room_name'] = $row['room_name'];
    $mail_previous['area_name'] = $row['area_name'];
    $mail_previous['type'] = $row['type'];
    $mail_previous['room_id'] = $row['room_id'];
    $mail_previous['repeat_id'] = $row['repeat_id'];
    $mail_previous['updated'] = getMailTimeDateString($row[8]);
    $mail_previous['area_admin_email'] = $row['area_admin_email'];
    $mail_previous['room_admin_email'] = $row['room_admin_email'];
    // If we use periods
    if ($enable_periods) {
        // If we delete a serie, start_time and end_time must
        // come from $tbl_repeat, not $tbl_entry.
        //
        // This is not a serie
        if (1 != $series) {
            list($mail_previous['start_period'], $mail_previous['start_date']) = getMailPeriodDateString($row['tbl_e_start_time']);
            list($mail_previous['end_period'], $mail_previous['end_date']) = getMailPeriodDateString($row['tbl_e_end_time'], -1);
            // need to make DST correct in opposite direction to entry creation
            // so that user see what he expects to see
            $mail_previous['duration'] = $row['tbl_e_duration'] - cross_dst($row['tbl_e_start_time'], $row['tbl_e_end_time']);
        } else {
            list($mail_previous['start_period'], $mail_previous['start_date']) = getMailPeriodDateString($row['tbl_r_start_time']);
            list($mail_previous['end_period'], $mail_previous['end_date']) = getMailPeriodDateString($row['tbl_r_end_time'], 0);
            // use getMailTimeDateString as all I want is the date
            $mail_previous['rep_end_date'] = getMailTimeDateString($row['tbl_r_end_date'], FALSE);
            // need to make DST correct in opposite direction to entry creation
            // so that user see what he expects to see
            $mail_previous['duration'] = $row['tbl_r_duration'] - cross_dst($row['tbl_r_start_time'], $row['tbl_r_end_time']);
            $mail_previous['rep_opt'] = "";
            switch ($row['rep_type']) {
                case 2:
                case 6:
                    $rep_day[0] = $row['rep_opt'][0] != "0";
                    $rep_day[1] = $row['rep_opt'][1] != "0";
                    $rep_day[2] = $row['rep_opt'][2] != "0";
                    $rep_day[3] = $row['rep_opt'][3] != "0";
                    $rep_day[4] = $row['rep_opt'][4] != "0";
                    $rep_day[5] = $row['rep_opt'][5] != "0";
                    $rep_day[6] = $row['rep_opt'][6] != "0";
                    if ($row['rep_type'] == 6) {
                        $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
                    } else {
                        $mail_previous['rep_num_weeks'] = "";
                    }
                    break;
                default:
                    $rep_day = array(0, 0, 0, 0, 0, 0, 0);
            }
            for ($i = 0; $i < 7; $i++) {
                $wday = ($i + $weekstarts) % 7;
                if ($rep_day[$wday]) {
                    $mail_previous['rep_opt'] .= day_name($wday) . " ";
                }
            }
            $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
        }
        toPeriodString($mail_previous['start_period'], $mail_previous['duration'], $mail_previous['dur_units']);
    } else {
        // This is not a serie
        if (1 != $series) {
            $mail_previous['start_date'] = getMailTimeDateString($row['tbl_e_start_time']);
            $mail_previous['end_date'] = getMailTimeDateString($row['tbl_e_end_time']);
            // need to make DST correct in opposite direction to entry creation
            // so that user see what he expects to see
            $mail_previous['duration'] = $row['tbl_e_duration'] - cross_dst($row['tbl_e_start_time'], $row['tbl_e_end_time']);
        } else {
            $mail_previous['start_date'] = getMailTimeDateString($row['tbl_r_start_time']);
            $mail_previous['end_date'] = getMailTimeDateString($row['tbl_r_end_time']);
            // use getMailTimeDateString as all I want is the date
            $mail_previous['rep_end_date'] = getMailTimeDateString($row['tbl_r_end_date'], FALSE);
            // need to make DST correct in opposite direction to entry creation
            // so that user see what he expects to see
            $mail_previous['duration'] = $row['tbl_r_duration'] - cross_dst($row['tbl_r_start_time'], $row['tbl_r_end_time']);
            $mail_previous['rep_opt'] = "";
            switch ($row['rep_type']) {
                case 2:
                case 6:
                    $rep_day[0] = $row['rep_opt'][0] != "0";
                    $rep_day[1] = $row['rep_opt'][1] != "0";
                    $rep_day[2] = $row['rep_opt'][2] != "0";
                    $rep_day[3] = $row['rep_opt'][3] != "0";
                    $rep_day[4] = $row['rep_opt'][4] != "0";
                    $rep_day[5] = $row['rep_opt'][5] != "0";
                    $rep_day[6] = $row['rep_opt'][6] != "0";
                    if ($row['rep_type'] == 6) {
                        $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
                    } else {
                        $mail_previous['rep_num_weeks'] = "";
                    }
                    break;
                default:
                    $rep_day = array(0, 0, 0, 0, 0, 0, 0);
            }
            for ($i = 0; $i < 7; $i++) {
                $wday = ($i + $weekstarts) % 7;
                if ($rep_day[$wday]) {
                    $mail_previous['rep_opt'] .= day_name($wday) . " ";
                }
            }
            $mail_previous['rep_num_weeks'] = $row['rep_num_weeks'];
        }
        toTimeString($mail_previous['duration'], $mail_previous['dur_units']);
    }
    1 == $series ? $mail_previous['rep_type'] = $row['rep_type'] : ($mail_previous['rep_type'] = 0);
    // return entry previous data as an array
    return $mail_previous;
}
        ?>
      </div>
      <div class="menu_box_bot"><img border="0" src="<?= ADMIN_BASE_URL ?>images/menubox_bottom.gif" alt="" /></div>
    </div>

<?php
if(isLoggedIn()) {
   $sql = 'SELECT feed_content.feed_id as feed_id, COUNT(content.id) as cnt '.
          'FROM feed_content '.
          'LEFT JOIN content ON feed_content.content_id = content.id '.
          'WHERE feed_content.moderation_flag IS NULL '.
          'GROUP BY feed_content.feed_id;';
   $res = sql_query($sql);

   $more_waiting = 0;
   for($i = 0;$row = sql_row_keyed($res,$i);++$i){
      $count = $row['cnt'];
      $feed = new Feed($row['feed_id']);
      if($feed->user_priv($_SESSION['user'], 'moderate',true)) {
         $mod_feeds[]="<p><a href=\"".ADMIN_URL."/moderate/feed/{$feed->id}\">" . htmlspecialchars($feed->name) . " ({$row['cnt']})</a></p>";
      } else {
         $more_waiting += $row['cnt'];
      }
   }
}
if(isset($mod_feeds) || ($more_waiting && isAdmin())) {
?>
    <div class="alert_box">
	   <div class="alert_box_inset">
        <div class="alert_box_padding">
          <h1><a href="<?=ADMIN_URL?>/moderate">Awaiting Moderation</a></h1>
  function stats_byscreen($time_period_in='yesterday'){
    
    $time_period = escape($time_period_in);

    $sql = "SELECT feed_id, " . $time_period . "_count FROM feed_content WHERE content_id = $this->id AND " . $time_period . "_count > 0";
    $res = sql_query($sql);
    $content_display_sum = 0;
    $i=0;
    while($row = sql_row_keyed($res, $i)){ //Generates a breakdown of displays per feed
      $content_display_sum += $row[$time_period . '_count'];
      $feed_distribution[$row['feed_id']] = $row[$time_period . '_count'];
      $i++;
    }
    if($i > 0){  //Verify the content has been shown somewhere before we do all this math
      foreach ($feed_distribution as $feed_id => $display_count){
        $sql2 = "SELECT screen_id, SUM(" . $time_period . "_count) as " . $time_period . "_count FROM position WHERE feed_id = $feed_id AND " . $time_period . "_count > 0 GROUP BY screen_id";
        $res2 = sql_query($sql2);
        $feed_display_sum = 0;
        $j = 0;
        while($row2 = sql_row_keyed($res2, $j)){ //Generates a breakdown of displays per feed
          $feed_display_sum += $row2[$time_period . '_count'];
          $tempscreen_distribution[$row2['screen_id']] = $row2[$time_period . '_count'] * $display_count / $content_display_sum;
          $j++;
        }
        $screen_distribution = array();
        foreach ($tempscreen_distribution as $screen_id => $temp_calc){ //Reduce that to be on a per position percentage
          if(!array_key_exists($screen_id, $screen_distribution)) {
            $screen_distribution[$screen_id] = 0;
          }
          $screen_distribution[$screen_id] += $temp_calc / $feed_display_sum;
        }
      }
      //Finally scale it up in terms of total content displayed
      foreach ($screen_distribution as $screen_id => $temp_calc){
          $screen_distribution[$screen_id] = round($temp_calc * $content_display_sum);
      }
      return $screen_distribution;
      } else {
        return 0; //The content hasn't been shown anywhere

      }
  }
Esempio n. 15
0
}elseif($type == 'all'){
  $sql_base .= '';
}
//Don't forget the ordering
$sql_base .= ' ORDER BY id';
//End ordering
if(is_numeric($count)){
	$sql_base .= " LIMIT $count";
}
//End SQL generation

//Run and process the query
$res = sql_query($sql_base);
if($res){
	$i=0;
	while($row = sql_row_keyed($res,$i)){
		$data[$i] = $row;
		$i++;
	}
}
//End processing the query

//Verify we got content
if(!isset($data) || count($data) <= 0){
	return false;
}
//End verification

//Now to start generating some display
if($format == 'raw'){
	$content = $data[0]; //For images we only generate the first one
	function get_all($where = ''){
		$sql = "SELECT id FROM screen $where";
		$res = sql_query($sql);
		$i=0;
		$found = false;
		while($row = sql_row_keyed($res,$i)){
			$found = true;
			$data[] = new Screen($row['id']);
			$i++;
		}
		if($found){
			return $data;
		} else {
			return false;
		}
	}
Esempio n. 17
0
function sql_select($table, $fields = "", $conditions = "", $extra = "", $debug = false)
{
    if ($fields && !is_array($fields)) {
        $fields = array($fields);
    }
    $query = 'SELECT ' . ($fields ? join(", ", $fields) : '*') . " FROM `{$table}`";
    if ($conditions) {
        $query .= " WHERE {$conditions} ";
    }
    if ($extra) {
        $query .= ' ' . $extra;
    }
    if ($debug) {
        echo $query;
    }
    $res = sql_query($query);
    $rows = array();
    $i = 0;
    if ($debug) {
        echo mysql_error();
    }
    while ($row = sql_row_keyed($res, $i++)) {
        if (isset($row[0])) {
            $rows[] = $row;
        }
    }
    if ($debug) {
        print_r($rows);
    }
    return $rows;
}
Esempio n. 18
0
function get_areas($all = FALSE)
{
    global $tbl_area;
    $users = array();
    $sql = "SELECT code, name FROM users";
    if (empty($all)) {
        $sql .= " WHERE disabled=0";
    }
    $sql .= " ORDER BY name";
    $res = sql_query($sql);
    if ($res === FALSE) {
        trigger_error(sql_error(), E_USER_WARNING);
    } else {
        for ($i = 0; $row = sql_row_keyed($res, $i); $i++) {
            $users[$row['code']] = $row['name'];
        }
    }
    return $users;
}
 function needs_update(){
     $sql = "SELECT COUNT(id) as need_update FROM content LEFT JOIN feed_content ON content.id = feed_content.content_id WHERE feed_content.feed_id = {$this->feed->id} AND feed_content.moderation_flag = 1 AND content.submitted > '{$this->last_update}'";
     $res = sql_query($sql);
     if($res){
         $data = sql_row_keyed($res,0);
         if($data['need_update'] > 0){
             return $data['need_update'];
         }
     }
     return 0;
 }
Esempio n. 20
0
	function destroy(){
		$sql = "DELETE FROM feed_content WHERE feed_id = $this->id";
		$res = sql_query($sql);
		if(!$res){
			return false; //Error unmapping content!
		}
		$sql1 = "SELECT field_id, screen_id FROM position WHERE feed_id = $this->id";
		$res1 = sql_query($sql1);
		if(!$res1){
			return false; //Error grabbing positions/fields
		}
		$i=0;
		while($row = sql_row_keyed($res1,$i)){
		    $field = new Field($row['field_id'],$row['screen_id']);
			$field->delete_feed($this->id);
			//$field->rebalance_scale();
		    $i++;
		}
		
		$sql = "DELETE FROM feed WHERE id = $this->id";
		$res = sql_query($sql);
		if(!$res){
			return false; //Error with the final delete!!!
		}
		$notify = new Notification();
		$notify->notify('feed', $this->id, 'user', $_SESSION['user']->id, 'delete');
		//Then we just clear the variables
		$this->id = '';
		$this->name = '';
      $this->description = '';
		$this->group_id='';
		$this->set = false;
		return true;
	}
Esempio n. 21
0
function convert_one_db($db)
{
    global $alterdatabasecharset;
    global $altertablecharset;
    global $charset;
    global $collate;
    global $printonly;
    global $db_handle;
    $db_cha = PMA_getDbCollation($db);
    if (substr($db_cha[0], 0, 4) == 'utf8') {
        // This doesn't work for me, but isn't a big deal, as the table
        // check below works
        echo "Skipping utf8 database '{$db}'\n";
        return;
    }
    sql_command("USE {$db}", $db_handle);
    $rs = sql_query("SHOW TABLES", $db_handle);
    if (!$rs) {
        echo "\n\n" . sql_error($db_handle) . "\n\n";
    } else {
        for ($i = 0; $data = sql_row($rs, $i, $db_handle); $i++) {
            echo "Converting '{$data['0']}' table...\n";
            $rs1 = sql_query("show FULL columns from {$data['0']}", $db_handle);
            if (!$rs1) {
                echo "\n\n" . sql_error($db_handle) . "\n\n";
            } else {
                for ($j = 0; $data1 = sql_row_keyed($rs1, $j, $db_handle); $j++) {
                    if (in_array(array_shift(split("\\(", $data1['Type'], 2)), array('char', 'varchar', 'tinytext', 'text', 'mediumtext', 'longtext', 'enum', 'set'))) {
                        if (substr($data1['Collation'], 0, 4) != 'utf8') {
                            $sq = "ALTER TABLE `{$data['0']}` CHANGE `" . $data1['Field'] . '` `' . $data1['Field'] . '` ' . $data1['Type'] . ' CHARACTER SET binary ' . ($data1['Default'] == '' ? '' : ($data1['Default'] == 'NULL' ? ' DEFAULT NULL' : ' DEFAULT \'' . addslashes($data1['Default']) . '\'')) . ($data1['Null'] == 'YES' ? ' NULL ' : ' NOT NULL');
                            if (!$printonly && !sql_query($sq, $db_handle)) {
                                echo "\n\n" . $sq . "\n" . sql_error($db_handle) . "\n\n";
                            } else {
                                if ($printonly) {
                                    echo $sq . "\n";
                                }
                                $sq = "ALTER TABLE `{$data['0']}` CHANGE `" . $data1['Field'] . '` `' . $data1['Field'] . '` ' . $data1['Type'] . " CHARACTER SET {$charset} " . ($collate == '' ? '' : "COLLATE {$collate}") . ($data1['Default'] == '' ? '' : ($data1['Default'] == 'NULL' ? ' DEFAULT NULL' : ' DEFAULT \'' . addslashes($data1['Default']) . '\'')) . ($data1['Null'] == 'YES' ? ' NULL ' : ' NOT NULL') . ($data1['Comment'] == '' ? '' : ' COMMENT \'' . addslashes($data1['Comment']) . '\'');
                                if (!$printonly && !sql_query($sq, $db_handle)) {
                                    echo "\n\n" . $sq . "\n" . sql_error($db_handle) . "\n\n";
                                } else {
                                    if ($printonly) {
                                        echo $sq . "\n";
                                    }
                                }
                            }
                            // end of if (!$printonly)
                        }
                        // end of if (substr)
                    }
                    // end of if (in_array)
                }
                // end of inner for
            }
            // end of if ($rs1)
            if ($altertablecharset) {
                $sq = 'ALTER TABLE `' . $data[0] . "` " . "DEFAULT CHARACTER SET {$charset} " . ($collate == '' ? '' : "COLLATE {$collate}");
                if ($printonly) {
                    echo $sq . "\n";
                } else {
                    if (!sql_query($sq, $db_handle)) {
                        echo "\n\n" . $sq . "\n" . sql_error($db_handle) . "\n\n";
                    }
                }
            }
            // end of if ($altertablecharset)
            print "done.<br>\n";
        }
        // end of outer for
    }
    // end of if (!$rs)
    if ($alterdatabasecharset) {
        $sq = 'ALTER DATABASE `' . $db . "` " . "DEFAULT CHARACTER SET {$charset} " . ($collate == '' ? '' : "COLLATE {$collate}");
        if ($printonly) {
            echo $sq . "\n";
        } else {
            if (!sql_query($sq, $db_handle)) {
                echo "\n\n" . $sq . "\n" . sql_error($db_handle) . "\n\n";
            }
        }
    }
    // end of if ($alterdatabasecharset)
}
    echo !empty($row['custom_html']) ? $row['custom_html'] . "\n" : "";
    echo "</div>\n";
}
// THE AREA FORM
if (isset($change_area) && !empty($area)) {
    // Only admins can see this form
    if (!$is_admin) {
        showAccessDenied($day, $month, $year, $area, "");
        exit;
    }
    // Get the details for this area
    $res = sql_query("SELECT * FROM {$tbl_area} WHERE id={$area} LIMIT 1");
    if (!$res) {
        fatal_error(0, get_vocab("error_area") . $area . get_vocab("not_found"));
    }
    $row = sql_row_keyed($res, 0);
    sql_free($res);
    // Get the settings for this area, from the database if they are there, otherwise from
    // the config file.    A little bit inefficient repeating the SQL query
    // we've just done, but it makes the code simpler and this page is not used very often.
    get_area_settings($area);
    echo "<form class=\"form_general\" id=\"edit_area\" action=\"edit_area_room.php\" method=\"post\">\n";
    echo "<fieldset class=\"admin\">\n";
    echo "<legend>" . get_vocab("editarea") . "</legend>\n";
    // Any error messages
    echo "<fieldset>\n";
    echo "<legend></legend>\n";
    if (FALSE == $valid_email) {
        echo "<p class=\"error\">" . get_vocab('invalid_email') . "</p>\n";
    }
    if (FALSE == $valid_resolution) {
Esempio n. 23
0
function system_info(){
    echo '<?xml version="1.0"?>';
    $sql = "SELECT id, name FROM feed WHERE type != 3";
    $res = sql_query($sql);
    $i=0;
?>

<feeds>
<?
    while($row = sql_row_keyed($res, $i)){
?>
    <feed>
        <id><?php 
echo $row['id'];
?>
</id>
        <name><?php 
echo $row['name'];
?>
</name>
    </feed>
<?
        $i++;
    }
?>
</feeds>
<?
    $sql = "SELECT name FROM type";
    $res = sql_query($sql);
    $i = 0;
?>
<types>
<?
    while($row = sql_row_keyed($res, $i)){
?>
    <type><?php 
echo $row['name'];
?>
</type>
<?
        $i++;
    }
?>
</types>
<?
}
Esempio n. 24
0
 print "<table id=\"edit_users_list\" class=\"admin_table\">\n";
 print "<thead>\n";
 print "<tr>";
 // Column headers (we don't use 'id' and 'password')
 foreach ($fields as $fieldname) {
     if ($fieldname != 'id' && $fieldname != 'password') {
         print "<th>" . get_loc_field_name($fieldname) . "</th>";
     }
 }
 // Last column which is an action button
 print "<th>" . get_vocab("action") . "</th>";
 print "</tr>\n";
 print "</thead>\n";
 print "<tbody>\n";
 $i = 0;
 while ($line = sql_row_keyed($list, $i++)) {
     print "<tr>\n";
     // Column contents
     foreach ($line as $key => $col_value) {
         // sql_row_keyed returns an array indexed by both index number annd key name,
         // so skip past the index numbers
         if (is_int($key)) {
             continue;
         }
         switch ($key) {
             case 'id':
                 $this_id = $col_value;
                 // Don't display it, but remember it.
                 break;
             case 'password':
                 break;
Esempio n. 25
0
 function has_ndc_rights()
 {
     if ($this->set) {
         $groups = implode(',', $this->groups);
         $sql = "SELECT COUNT(id) AS f_count FROM feed WHERE type = 4 AND group_id IN ({$groups})";
         $res = sql_query($sql);
         if ($res && ($data = sql_row_keyed($res, 0)) && $data['f_count'] > 0) {
             return true;
         } else {
             return false;
         }
     }
 }