<?php
/*
This file is part of Thomas Bley's moregroupware webmail2/calendar2/admin2 module. (tb-mgw)

More information:
-----------------

Simple Groupware Solutions Thomas Bley
Fichtenstr. 23
Germany, 85640 Putzbrunn

Contact:
--------

info@simple-groupware.de

http://www.simple-groupware.de


Copyright 2002-2003 Thomas Bley
tb-mgw is distributed under the terms of the GNU General Public License 

tb-mgw is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

tb-mgw is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with tb-mgw; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// admin2_func
// Moregroupware.org

define('ADM2_DIR', ROOTPATH."/modules/webmail2/");

if (get_magic_quotes_gpc() == 1){
  if (is_array($_POST) and count($_POST)>0)
  while (list ($key, $val) = each ($_POST)){
    $_POST[$key] = stripslashes_array($val);
  }
  if (is_array($_GET) and count($_GET)>0)
  while (list ($key, $val) = each ($_GET)){
    $_GET[$key] = stripslashes_array($val);
  }
  if (is_array($_COOKIE) and count($_COOKIE)>0)
  while (list ($key, $val) = each ($_COOKIE)){
    $_COOKIE[$key] = stripslashes_array($val);
  }
}


function draw_array($the_array,$second) {
  if (is_array($the_array)) {
  	$return_string = "array(";
    foreach ($the_array as $the_arrayer) {
      if (is_array($the_arrayer)) {
		$return_string .= draw_array($the_arrayer,false);
	  } else {
	    $return_string .= "\"".addcslashes(addslashes($the_arrayer),"\$")."\",";
	  }
	}
  	$return_string .= ")";
	if (!$second) {$return_string .= ",\n";} else {$return_string .= ";\n";}
  } else {
    $return_string .= "\"".addcslashes(addslashes($the_array),"\$")."\"";
	if (!$second) {$return_string .= ",\n";} else {$return_string .= ";\n";}
  }
  return $return_string;
}

function getallusers2() {
  global $conn;
  $sql = "select username,id from mgw_users order by username";
  if(!$res = $conn->Execute($sql)) die(showSQLerror($sql, $conn->ErrorMsg(), __LINE__,__FILE__));
  $users = array();
  while ($row = $res->FetchRow()) {
    $users[$row["id"]] = strtolower($row["username"]);
  }
  return $users;
}

function get_group_name($groupid) {
  global $conn;

  $sql = "SELECT name FROM mgw_groups where id=".(int)$groupid;
  if(!$res2 = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
  $row2 = $res2->FetchRow();
	  
  if (isset($row2["name"]) and $row2["name"]!="") return $row2["name"];
    else return "_";
}

function get_calendar_name($id) {
  global $conn;

  if (isModuleInstalled("calendar2")) {
  
    $sql = "SELECT dcalendar FROM mgw_calendar2_cals where id=".(int)$id;
    if(!$res = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
    $row = $res->FetchRow();

    if (isset($row["dcalendar"]) and $row["dcalendar"]!="") {
      if (is_numeric($row["dcalendar"])) {
	    return get_group_name($row["dcalendar"]);
  	  }
      if ($row["dcalendar"][0]=="#" or $row["dcalendar"][0]=="@") return substr($row["dcalendar"],1);
    
	  return ucfirst($row["dcalendar"]);
    } else {
      return "empty";
    }
  } else return "empty";
}

function my_cmp ($a, $b) {
  if (!is_array($a) or !is_array($b) or $a[1] == $b[1]) return 0;
  return ($a[1] < $b[1]) ? -1 : 1;
}

function get_calendar_id($calendar) {
  global $conn;

  $sql = "SELECT id FROM mgw_calendar2_cals where dcalendar=".$conn->Quote($calendar);
  if(!$res = $conn->Execute($sql)) exit(showSQLerror($sql, $conn->ErrorMsg(), __LINE__, __FILE__));
  $row = $res->FetchRow();

  if (isset($row["id"]) and is_numeric($row["id"])) return $row["id"];
    else return 0;
}


?>
