<commit_before><?php
// $Id: /cvsroot/tikiwiki/tiki/lib/calendar/calendarlib.php,v 1.75.2.5 2008-03-18 18:19:08 sylvieg Exp $
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("location: index.php");
  exit;
}

if (!defined('weekInSeconds')) define('weekInSeconds', 604800);

class CalendarLib extends TikiLib {
	function convertSortMode($sort_mode) {
		$tmp = explode("_",$sort_mode);
		if (count($tmp) == 2) {
			if ($tmp[0] == "categoryName" || $tmp[0] == "locationName")
				return "name " . $tmp[1];
		}
		return parent::convertSortMode($sort_mode);
	}

	function list_calendars($offset = 0, $maxRecords = -1, $sort_mode = 'name_asc', $find = '') {
		$mid = '';
		$res = array();
		$bindvars = array();
		if ($find) {
			$mid = "where tcal.`name` like ?";
			$bindvars[] = '%'.$find.'%';
		}
		// Use perspectives
		global $categlib; require_once( 'lib/categories/categlib.php' );
		$category_jails = $categlib->get_jail();

		if( ! isset( $filter['categId'] ) && ! empty( $category_jails ) ) {
			$filter['categId'] = $category_jails;
		}
		
		$distinct = '';
		if (!empty($filter)) {
			$tmp_mid = array();
			foreach ($filter as $type=>$val) {
				if ($type == 'categId') {
					$categories = $categlib->get_jailed( (array) $val );

					$cat_count = count( $categories );
					$join_tables .= " inner join `tiki_objects` as tob on (tob.`itemId`= tcal.`calendarId` and tob.`type`= ?) inner join `tiki_category_objects` as tc on (tc.`catObjectId`=tob.`objectId` and tc.`categId` IN(" . implode(', ', array_fill(0, $cat_count, '?')) . "))";
					if ($mid = "")
						$getUncategorized = " where (tob.`itemId`=tcal.`calendarId` and )";
					else
						$getUncategorized = "and (tob.`itemId`!=tcal.`calendarId` and tob.`type`='calendar')";

					if( $cat_count > 1 ) {
						$distinct = ' DISTINCT ';
					}

					$join_bindvars = array_merge(array('calendar'), $categories);
				} 
			}
			if (!empty($tmp_mid)) {
				$mid .= empty($mid) ? ' where (' : ' and (';
				$mid .= implode( ' and ', $tmp_mid ) . ')';
			}
		}
		
		$bindvars = array_merge($bindvars, $join_bindvars);

		$query = "select $distinct * from `tiki_calendars` as tcal $join_tables $mid order by tcal.".$this->convertSortMode($sort_mode);
		$result = $this->query($query,$bindvars,$maxRecords,$offset);
		$query_cant = "select count(*) from `tiki_calendars` $mid";
		$cant = $this->getOne($query_cant,$bindvars);

		$res = array();
		while ($r = $result->fetchRow()) {
			$k = $r["calendarId"];
			$res2 = $this->query("select `optionName`,`value` from `tiki_calendar_options` where `calendarId`=?",array((int)$k));
			while ($r2 = $res2->fetchRow()) {
				$r[$r2['optionName']] = $r2['value'];
			}
			$res["$k"] = $r;
		}
		$retval["data"] = $res;
		$retval["cant"] = $cant;
		return $retval;
	}

	// give out an array with Ids viewable by $user
	function list_user_calIds() {
		global $user;
		if ($user) {<commit_msg>[FIX] PHP Warnings<commit_after><?php
// $Id: /cvsroot/tikiwiki/tiki/lib/calendar/calendarlib.php,v 1.75.2.5 2008-03-18 18:19:08 sylvieg Exp $
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("location: index.php");
  exit;
}

if (!defined('weekInSeconds')) define('weekInSeconds', 604800);

class CalendarLib extends TikiLib {
	function convertSortMode($sort_mode) {
		$tmp = explode("_",$sort_mode);
		if (count($tmp) == 2) {
			if ($tmp[0] == "categoryName" || $tmp[0] == "locationName")
				return "name " . $tmp[1];
		}
		return parent::convertSortMode($sort_mode);
	}

	function list_calendars($offset = 0, $maxRecords = -1, $sort_mode = 'name_asc', $find = '') {
		$mid = '';
		$res = array();
		$bindvars = array();
		if ($find) {
			$mid = "where tcal.`name` like ?";
			$bindvars[] = '%'.$find.'%';
		}
		// Use perspectives
		global $categlib; require_once( 'lib/categories/categlib.php' );
		$category_jails = $categlib->get_jail();

		if( ! isset( $filter['categId'] ) && ! empty( $category_jails ) ) {
			$filter['categId'] = $category_jails;
		}
		
		$distinct = '';
		if (!empty($filter)) {
			$tmp_mid = array();
			foreach ($filter as $type=>$val) {
				if ($type == 'categId') {
					$categories = $categlib->get_jailed( (array) $val );

					$cat_count = count( $categories );
					$join_tables .= " inner join `tiki_objects` as tob on (tob.`itemId`= tcal.`calendarId` and tob.`type`= ?) inner join `tiki_category_objects` as tc on (tc.`catObjectId`=tob.`objectId` and tc.`categId` IN(" . implode(', ', array_fill(0, $cat_count, '?')) . "))";
					if ($mid = "")
						$getUncategorized = " where (tob.`itemId`=tcal.`calendarId` and )";
					else
						$getUncategorized = "and (tob.`itemId`!=tcal.`calendarId` and tob.`type`='calendar')";

					if( $cat_count > 1 ) {
						$distinct = ' DISTINCT ';
					}

					$join_bindvars = array_merge(array('calendar'), $categories);
				} 
			}
			if (!empty($tmp_mid)) {
				$mid .= empty($mid) ? ' where (' : ' and (';
				$mid .= implode( ' and ', $tmp_mid ) . ')';
			}
		}
		if (is_array($join_bindvars)) {
			$bindvars = array_merge($bindvars, $join_bindvars);
		}

		$query = "select $distinct * from `tiki_calendars` as tcal $join_tables $mid order by tcal.".$this->convertSortMode($sort_mode);
		$result = $this->query($query,$bindvars,$maxRecords,$offset);
		$query_cant = "select count(*) from `tiki_calendars` $mid";
		$cant = $this->getOne($query_cant,$bindvars);

		$res = array();
		while ($r = $result->fetchRow()) {
			$k = $r["calendarId"];
			$res2 = $this->query("select `optionName`,`value` from `tiki_calendar_options` where `calendarId`=?",array((int)$k));
			while ($r2 = $res2->fetchRow()) {
				$r[$r2['optionName']] = $r2['value'];
			}
			$res["$k"] = $r;
		}
		$retval["data"] = $res;
		$retval["cant"] = $cant;
		return $retval;
	}

	// give out an array with Ids viewable by $user
	function list_user_calIds() {
		global $user;
		if ($user) {
{'fraction_non_alphanumeric': 0.20668542114843622, 'fraction_numerical': 0.012576534833691875, 'mean_word_length': 3.870265914585012, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7193226', 'n_tokens_mistral': 2610, 'n_tokens_neox': 2281, 'n_words': 462}