summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 893ddad)
raw | patch | inline | side by side (parent: 893ddad)
author | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 9 Jan 2008 16:22:31 +0000 (16:22 +0000) | ||
committer | cajus <cajus@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Wed, 9 Jan 2008 16:22:31 +0000 (16:22 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8272 594d385d-05f5-0310-b6e9-bd551577e9d8
19 files changed:
index 33da6744814e1b0fbb3be9d18e4481188afb2a7d..971f797dcb56aeca5cbbb16d7a06a633013cf375 100644 (file)
--- a/gosa-core/html/main.php
+++ b/gosa-core/html/main.php
/* Basic setup, remove eventually registered sessions */
require_once ("../include/php_setup.inc");
require_once ("functions.inc");
-require_once ("functions_FAI.inc");
+#require_once ("functions_FAI.inc");
/* Set header */
header("Content-type: text/html; charset=UTF-8");
diff --git a/gosa-core/include/class_debconfTemplate.inc b/gosa-core/include/class_debconfTemplate.inc
+++ /dev/null
@@ -1,428 +0,0 @@
-<?php
-
-class debconf
-{
- var $package= "";
- var $language= "";
- var $loaded_template= FALSE;
- var $template_directory= "";
- var $template= array();
-
-
- function debconf($package= "", $language= "")
- {
- $this->set_language($language);
- $this->set_package($package);
- }
-
-
- function set_package($package)
- {
- $this->package= $package;
- }
-
-
- function set_template_directory($directory)
- {
- if (is_dir($directory) && is_readable($directory)){
- $this->template_directory = $directory;
- return TRUE;
- }
-
- $this->template_directory= "";
- return FALSE;
- }
-
-
- function set_language($language)
- {
- $this->language= $language;
- }
-
-
- function load()
- {
- if( TRUE === $this->has_template() ) {
-
- /* Try to load package based template file */
- $this->template= array();
-
- /* Read template array */
- $post_name = 0;
- $langcode = $this->language.".UTF-8";
- $in_description = FALSE;
- $got_local_description = FALSE;
-
- /* get filename */
- $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates");
-
- /* Check if file is readable */
- if (!is_file($filename) || !is_readable($filename)){
- return(FALSE);
- }
-
- /* Open file and read content line by line */
- $fh= fopen($filename, 'r');
-
- /* While the file handle is valid && there is still data to read -> parse configuration file */
- while ($fh && !feof($fh)){
- $line= fgets($fh, 1024);
-
- /* Reset description flag */
- if ($in_description && !preg_match("/^ /", $line)){
- $in_description= FALSE;
- }
-
- /* Template header */
- if (preg_match("/^Template: /", $line)){
- $post_name ++;
- $name= trim(preg_replace("/^Template: (.*)$/", "\\1", $line));
- $this->template[$post_name]['Name'] = $name;
- $this->template[$post_name]['Default'] ="";
-
- $got_local_description= FALSE;
- continue;
- }
-
- /* Get type */
- if (preg_match("/^Type: /", $line)){
- $type= trim(preg_replace("/^Type: (.*)$/", "\\1", $line));
- $this->template[$post_name]['Type']= $type;
- continue;
- }
-
- /* Get default */
- if (preg_match("/^Default: /", $line)){
- $this->template[$post_name]['Default']= "";
- $default= trim(preg_replace("/^Default: (.*)$/", "\\1", $line));
- $this->template[$post_name]['Default']= $default;
- continue;
- }
-
- /* Get description */
- if (!$got_local_description && preg_match("/^Description: /", $line)){
- $this->template[$post_name]['Description']= "";
- $description= trim(preg_replace("/^Description: (.*)$/", "\\1", $line));
- $this->template[$post_name]['Topic']= $description;
- $this->template[$post_name]['Description']= "";
- $in_description= TRUE;
- continue;
- }
-
- /* Fill description */
- if (!$got_local_description && $in_description){
- $description= preg_replace("/^ (.*)$/", "\\1", $line);
- $this->template[$post_name]['Description'].= $description;
- continue;
- }
-
- /* Get local description */
- if (preg_match("/^Description-$langcode: /", $line)){
- $description= trim(preg_replace("/^Description-$langcode: (.*)$/", "\\1", $line));
- $this->template[$post_name]['Topic']= $description;
- $in_description= TRUE;
- $got_local_description= TRUE;
- $this->template[$post_name]['Description']= "";
- continue;
- }
-
- /* Fill local description */
- if ($got_local_description && $in_description){
- $description= preg_replace("/^ (.*)$/", "\\1", $line);
- $this->template[$post_name]['Description'].= $description;
- continue;
- }
-
- /* Get native choices */
- if (preg_match("/^Choices: /", $line)){
- $type= trim(preg_replace("/^Choices: (.*)$/", "\\1", $line));
- $this->template[$post_name]['Choices']= $type;
- }
-
- /* Get local choices */
- if (preg_match("/^Choices-$langcode: /", $line)){
- $type= trim(preg_replace("/^Choices-$langcode: (.*)$/", "\\1", $line));
- $this->template[$post_name]['Choices-local']= $type;
- }
-
- }
-
- fclose($fh);
- $this->loaded_template= TRUE;
-
- $tmp= array();
- foreach($this->template as $post_name => $template){
- $template['post_name'] = "post_".$post_name;
- $tmp[] = $template;
- }
- $this->template = $tmp;
-
- return (TRUE);
- }
-
- $this->loaded_template= FALSE;
- return (FALSE);
- }
-
-
- function has_template()
- {
- /* Reject requests, if parameters are not set */
- if ($this->package == "" || $this->template_directory == ""){
- return (FALSE);
- }
- $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates");
- return (is_file($filename) && is_readable($filename));
- }
-
-
- /* Check if some fields are posted */
- function PostCheck()
- {
- /* Walk through all template variables */
- foreach($this->template as $post_name => $entry){
-
- /* Check if this var is set*/
- if(isset($_POST[$entry['post_name']])){
-
- /* special handling for arrays */
- if(is_array($_POST[$entry['post_name']])){
- $str = "";
- foreach($_POST[$entry['post_name']] as $val){
- $str.= $val.", ";
- }
- $str = preg_replace("/\,\ $/","",$str);
- $this->template[$post_name]['Default'] = $str;
- }else{
- $this->template[$post_name]['Default'] = $_POST[$entry['post_name']];
- }
- }
- }
-
- foreach($this->template as $post_name => $entry){
- if(isset($_POST["multi-".$entry['post_name']])){
- $this->template[$post_name]['Default']= "";
- foreach($_POST as $name => $value){
- if(preg_match("/".$entry['post_name']."-multi-/",$name)){
- $this->template[$post_name]['Default'] .= $value.", ";
- }
- }
- $this->template[$post_name]['Default'] = preg_replace("/, $/","",$this->template[$post_name]['Default']);
- }
- }
-
-
- }
-
-
- /* This funtion sets the defualt value */
- function SetDefault($var,$val)
- {
- if ($this->loaded_template) {
- foreach($this->template as $key => $tmp){
- if($tmp['Name'] == $var ){
- $this->template[$key]['Default'] = $val;
- }
- }
- }
- }
-
-
- /* Display all possible options in html*/
- function get_dialog()
- {
- if ($this->loaded_template) {
- $result= "<table summary=''>";
-
- foreach ($this->template as $post_name => $entry){
-
- $types= array("boolean" => "", "multiselect" => "", "note" => "",
- "password" => "", "select" => "", "string" => "", "text" => "", "title" => "");
-
- /* Check if type is available */
- if ((isset($entry['Type']))&&(isset($types[$entry['Type']]))){
-
- /* Produce type specific output */
- $fn= "render_".$entry['Type'];
- $str = $this->$fn($entry);
- if(!empty($str)){
- $result.=$str."<tr><td colspan='2'><p class='seperator'> </p></td></tr>";
- }
- } else {
- //php_error(E_WARNING, "An unknown type has been specified in the debconf template. Please fix.");
- }
- }
-
-
- $result .= "<input type='hidden' post_name='check_post' value='1'></table>";
- return ($result);
- } else {
- return _("This package has no debconf options.");
- }
- }
-
-
- function render_boolean($data)
- {
-
- $post_name= $data['post_name'];
- $result="
- <tr>
- <td valign='top' style='width:100%'>
- <h2>".$data['Topic']."</h2>".$data['Description']."
- </td>
- <td style=\"white-space:nowrap; vertical-align:top; border-left: 1px solid rgb(160, 160, 160);\">";
-
- foreach(array("true","false") as $value){
- if($data['Default'] == $value){
- $result.="<input type='radio' name='".$data['post_name']."' value='".$value."' checked>"._($value);
- }else{
- $result.="<input type='radio' name='".$data['post_name']."' value='".$value."' >"._($value);
- }
- $result.="<br>";
- }
-
- $result.= "
- </td>
- </tr>
- ";
-
- return ($result);
- }
-
-
- function render_multiselect($data)
- {
- $post_name= $data['post_name'];
- if (preg_match('/\$\{/', $data['Choices'])){
- $result= $this->render_string($data);
- } else {
- $choices= "";
- foreach (split(", ", $data['Choices']) as $choice){
- $choices[]= $choice;
- }
-
-
- $result="
- <tr>
- <td valign='top'>
- <h2>".$data['Topic']."</h2>".$data['Description']."
- </td>
- <td valign='top' style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\">
- <input type='hidden' name='multi-".$post_name."' value='1'>
- ";
-
- $defs = split(", ",$data['Default']);
- foreach($choices as $value){
- if(in_array($value,$defs)){
- $result.="\n<input name='".$post_name."-multi-".$value."' type='checkbox' value='".htmlentities($value)."' checked>".$value."<br>";
- }else{
- $result.="\n<input name='".$post_name."-multi-".$value."' type='checkbox' value='".htmlentities($value)."'>".$value."<br>";
- }
- }
-
- $result .= "</td>
- </tr>
- ";
- }
-
- return ($result);
- }
-
-
- function render_note($data)
- {
- /* Ignore notes, they do not makes sense, since we don't get any
- chance to test entered values... */
- return ("");
- }
-
-
- function render_password($data)
- {
- $result= "";
- $result.= "<tr><td valign='top'>";
- $result.= "<h2>".$data['Topic']."</h2>".$data['Description']."</td><td style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\"> <input type='text' name='".$data['post_name']."' value='".$data['Default']."'></b><br><br>";
- $result.= $data['Description'];
- $result.= "</td>";
-
- return ($result);
- }
-
-
- function render_select($data)
- {
- $post_name= $data['post_name'];
-
- if (preg_match('/\$\{/', $data['Choices'])){
- $choices= array("Need to use some text...");
- } else {
- $choices= "";
- foreach (split(", ", $data['Choices']) as $choice){
- $choices[]= $choice;
- }
- }
-
-
- $result="
-
- <tr>
- <td valign='top'>
- <h2>".$data['Topic']."</h2>".$data['Description']."
- </td>
- <td valign='top' style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\">
- ";
-
- foreach($choices as $value){
- if($data['Default'] == $value){
- $result.="\n<input type='radio' name='".$post_name."' value='".htmlentities($value)."' checked >".htmlentities($value)."<br>";
- }else{
- $result.="\n<input type='radio' name='".$post_name."' value='".htmlentities($value)."'>".htmlentities($value)."<br>";
- }
- }
-
- $result.= "
-
- </td>
- </tr>
- ";
-
- return ($result);
- }
-
-
- function render_string($data)
- {
- $result= "
- <tr>
- <td valign='top'>
- <h2>".$data['Topic']."</h2>".$data['Description']."
- </td>
- <td style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\" valign='top'>
- <input type='text' name='".$data['post_name']."' value='".$data['Default']."' style='width:300px;'>
- </td>
- </tr>
- ";
-
- return ($result);
- }
-
-
- function render_text($data)
- {
- /* Ignore text messages, they are normally used for status hints. */
- return ("");
- }
-
-
- function render_title($data)
- {
- /* Ignore text messages, they are normally used for status hints. */
- return ("");
- }
-
-}
-
-
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-core/include/class_dhcpPlugin.inc b/gosa-core/include/class_dhcpPlugin.inc
+++ /dev/null
@@ -1,208 +0,0 @@
-<?php
-/*
- This code is part of GOsa (https://gosa.gonicus.de)
- Copyright (C) 2003-2007 Cajus Pollmeier
-
- This program 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.
-
- This program 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 this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-class dhcpPlugin extends plugin
-{
- /* Used attributes */
- var $cn= "";
- var $orig_cn= "";
- var $options= array();
- var $statements= array();
-
- /* Subobjects */
- var $network;
- var $advanced;
-
- /* attribute list for save action */
- var $attributes= array();
- var $objectclasses= array();
-
- function dhcpPlugin($attrs)
- {
- /* Load statements / options */
- if (is_array($attrs)){
- $this->dn= $attrs['dn'];
- $this->cn= $attrs['cn'][0];
- $this->new= FALSE;
-
- /* Load options */
- if (isset($attrs['dhcpOption'])){
- foreach ($attrs['dhcpOption'] as $opt){
- $idx= preg_replace('/\s.+$/', '', $opt);
- if ($idx == $opt){
- $value= "";
- } else {
- $value= preg_replace('/^[^\s]+\s/', '', $opt);
- }
- $this->options[$idx]= $value;
- }
- }
-
- /* Load statements */
- if (isset($attrs['dhcpStatements'])){
- foreach ($attrs['dhcpStatements'] as $opt){
- $idx= preg_replace('/\s.+$/', '', $opt);
- if ($idx == $opt){
- $value= "";
- } else {
- $value= preg_replace('/^[^\s]+\s/', '', $opt);
- }
- $this->statements[$idx]= $value;
- }
- }
-
- } else {
- /* We keep the parent dn here if it's new */
- $this->dn= $attrs;
- $this->new= TRUE;
- }
-
- /* Load network module */
- $this->network= new dhcpNetwork();
- $this->network->options= $this->options;
- $this->network->statements= $this->statements;
- $this->advanced= new dhcpAdvanced();
- $this->advanced->options= $this->options;
- $this->advanced->statements= $this->statements;
-
- /* Save CN for later reference */
- $this->orig_cn= $this->cn;
- }
-
- function execute()
- {
- return ("");
- }
-
-
- function remove_from_parent()
- {
- }
-
-
- /* Save data to object */
- function save_object()
- {
- /* Strip network objects */
- foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){
- unset($this->options[$toberemoved]);
- }
- foreach (array("filename", "next-server") as $toberemoved){
- unset($this->statements[$toberemoved]);
- }
-
- /* Save sub-objects */
- $this->network->save_object();
- $this->advanced->save_object();
-
- /* Merge arrays for advanced view */
- foreach (array("options", "statements") as $type){
- $this->advanced->$type= $this->$type + $this->network->$type;;
- }
- }
-
-
- /* Check values */
- function check()
- {
- $message= array();
- return $message;
- }
-
-
- /* Save to LDAP */
- function save()
- {
- /* Merge arrays for network and advanced view */
- foreach (array("options", "statements") as $type){
- $this->$type= $this->$type + $this->network->$type + $this->advanced->$type;
- }
-
- /* Add cn if we're new */
- if ($this->new){
- $this->dn= "cn=".$this->cn.",".$this->dn;
- } else {
- $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn);
- }
-
- /* Assemble new entry - options */
- $this->attrs['dhcpOption']= array();
- if (isset ($this->options) && count ($this->options)){
- foreach ($this->options as $key => $val){
- $this->attrs['dhcpOption'][]= "$key $val";
- }
- }
-
- /* Assemble new entry - statements */
- $this->attrs['dhcpStatements']= array();
- if (isset ($this->statements) && count ($this->statements)){
- foreach ($this->statements as $key => $val){
- if ($val != ""){
- $this->attrs['dhcpStatements'][]= "$key $val";
- } else {
- $this->attrs['dhcpStatements'][]= "$key";
- }
- }
- }
-
- /* Move dn to the result */
- $this->attrs['dn']= $this->dn;
- $this->attrs['cn']= array($this->cn);
- $this->attrs['objectClass']= $this->objectclasses;
- $this->attrs['MODIFIED']= TRUE;
-
- return ($this->attrs);
- }
-
-
- function removeAttrs($name, $type)
- {
- $new= array();
- foreach ($this->attrs[$type] as $value){
- if (!preg_match("/^$name /", $value)){
- $new[]= $value;
- }
- }
- $this->attrs[$type]= $new;
- }
-
-
- function removeOption($name)
- {
- $this->removeAttrs($name, 'dhcpOption');
- }
-
-
- function removeStatement($name)
- {
- $this->removeAttrs($name, 'dhcpStatement');
- }
-
-
- function fix_options()
- {
- foreach (array('domain-name-servers') as $key){
- unset ($this->options[$key]);
- }
- }
-
-}
-
-?>
diff --git a/gosa-core/include/class_glpi.inc b/gosa-core/include/class_glpi.inc
+++ /dev/null
@@ -1,1777 +0,0 @@
-<?php
-
-
-class glpiDB{
-
- var $user ="";
- var $password ="";
- var $server ="";
- var $db ="";
-
- var $is_connected = 0;
- var $handle = NULL;
-
- var $lasterror ="";
-
- var $deviceMappingGOsaGlpi;
- var $deviceMappingTableNameID;
-
- function glpiDB($server,$user,$pwd,$db){
- $this->server = $server;
- $this->user = $user;
- $this->password = $pwd;
- $this->db = $db;
-
- $this->handle = @mysql_connect($this->server,$this->user,$this->password);
-
- if($this->handle){
- $this->is_connected = true;
- $this->SelectDB($this->db);
- }
- $this->deviceMappingGOsaGlpi = array(
- "glpi_device_case" => "case",
- "glpi_device_control" => "control",
- "glpi_device_drive" => "drive",
- "glpi_device_gfxcard" => "gfxcard",
- "glpi_device_hdd" => "hdd",
- "glpi_device_iface" => "iface",
- "glpi_device_moboard" => "moboard",
- "glpi_device_pci" => "pci",
- "glpi_device_power" => "power",
- "glpi_device_processor" => "processor",
- "glpi_device_ram" => "ram",
- "glpi_monitors" => "monitor",
- "glpi_device_sndcard" => "sndcard");
-
- $this->deviceMappingTableNameID = array( "moboard" => 1,
- "processor" => 2,
- "ram" => 3,
- "hdd" => 4,
- "iface" => 5,
- "drive" => 6,
- "control" => 7,
- "gfxcard" => 8,
- "sndcard" => 9,
- "pci" => 10,
- "case" => 11,
- "power" => 12);
-
-
- }
-
- function SelectDB()
- {
- if($this->is_connected){
- mysql_select_db($this->db,$this->handle);
- }
- }
-
-
- /* This functions checks if the selected computer/network
- device is already available in the db
- */
- function is_account($dn)
- {
- if(!$this->is_connected){
- $this->lasterror ="Can't query anything, if we aren't connected.";
- return(false);
- }else{
- $qry = "SELECT * FROM glpi_computers WHERE name='".$dn."';";
- $res = $this->query($qry);
- if(count($res)==0){
- return(false);
- }else{
- return(true);
- }
- }
- }
-
- /* this function queries everything
- */
- function query($qry)
- {
- if(!$this->is_connected){
- $this->lasterror ="Can't query anything, if we aren't connected.";
- return(false);
- }else{
- $ret =array();
- $res = mysql_query($qry,$this->handle);
-
- while($rs = @mysql_fetch_array($res,MYSQL_ASSOC)){
- $ret[]=$rs;
- }
- return($ret);
- }
- }
-
- /* System types
- Returns all defined system types
- */
- function getSystemTypes()
- {
- if($this->is_connected){
- $ret = array();
- $tmp = ($this->query("SELECT * FROM glpi_type_computers;"));
- foreach($tmp as $t){
- $ret[$t['ID']]=$t['name'];
- }
- asort($ret);
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* System types
- Update a system type
- */
- function updateSystemType($name,$id)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";");
- if(isset($tmp[0])){
- return($this->query("UPDATE glpi_type_computers SET name='".$name."' WHERE ID=".$id.";"));
- }else{
- echo "can't update not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* System types
- Add one entry to the system types
- */
- function addSystemType($name)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE name='".$name."';");
- if(isset($tmp[0])){
- echo "such an entry already exists";
- return(false);
- }else{
- return($this->query("INSERT INTO glpi_type_computers (name) VALUES ('".$name."');"));
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* System types
- Remove one entry from the system types (specified by ID=$id)
- */
- function removeSystemType($id)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";");
- if(isset($tmp[0])){
- return($this->query("DELETE FROM glpi_type_computers WHERE ID=".$id.";"));
- }else{
- echo "can't remove not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* System type is used */
- function is_systemTypeUsed($ID){
- if($this->is_connected){
- $ret = array();
- $qry="SELECT name,type FROM glpi_computers WHERE type=".$ID." LIMIT 3;";
- $res = $this->query($qry);
- foreach($res as $val){
- $ret[$val['name']] = $val['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
- /* Manufacturer
- Returns all defined manufacturers
- */
- function getEnterprises()
- {
- if($this->is_connected){
- $ret = array();
- $tmp = $this->query("SELECT * FROM glpi_enterprises ORDER BY name;");
- foreach($tmp as $t){
- $ret[$t['ID']]=$t['name'];
- }
-
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Manufacturer
- Returns single manufacturer
- */
- function getEnterprise($id)
- {
- if($this->is_connected){
- $ret = array();
- $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID=".$id.";");
- return($tmp);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Manufacturer
- Updates already existing manufacturer
- */
- function updateEnterprise($array,$id)
- {
- if(!is_array($array)){
- echo "updateEnterprisesType: first paraeter must be an array";
- }elseif($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID='".$id."';");
- if(isset($tmp[0])){
- $atr = array("ID","name","type","address","website","phonenumber","comments","deleted","fax","email");
-
- $v = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $v .= " ".$at."='".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "updateEnterprisesType: no attributes given ";
- return(false);
- }else{
- $v = preg_replace("/, $/","",$v);
- return($this->query("UPDATE glpi_enterprises SET ".$v." WHERE ID='".$id."';"));
- }
- }else{
- echo "can't update not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Manufacturer
- Add new manufacturer
- */
- function addEnterprise($array)
- {
- if(!is_array($array)){
- echo "addUser: first paraeter must be an array";
- }elseif($this->is_connected){
- $atr = array("ID","name","type","address","website","phonenumber","comments","deleted","fax","email");
- $v = "";
- $a = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $a .= $at.", ";
- $v .= "'".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "addUser: no attributes given ";
- return(false);
- }else{
- $a = preg_replace("/, $/","",$a);
- $v = preg_replace("/, $/","",$v);
- return($this->query("INSERT INTO glpi_enterprises (".$a.") VALUES (".$v.");"));
- }
-
- }else{
- echo "not connected";
- return(false);
- }
-
- }
-
- /* Manufacturer
- remove manufacturer
- */
- function removeEnterprise($id)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID=".$id.";");
- if(isset($tmp[0])){
- return($this->query("DELETE FROM glpi_enterprises WHERE ID=".$id.";"));
- }else{
- echo "can't remove not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Operating systems
- Returns all OSs
- */
- function getOSTypes($keys = false)
- {
- if($this->is_connected){
- $ret = array();
- $tmp=($this->query("SELECT * FROM glpi_dropdown_os ORDER by name;"));
-
- if($keys){
- foreach($tmp as $t){
- $ret[$t['name']]=$t['ID'];
- }
- }else{
- foreach($tmp as $t){
- $ret[$t['ID']]=$t['name'];
- }
- }
- return($ret);
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Operating system is used ? */
- function is_osUsed($ID){
- if($this->is_connected){
- $ret = array();
- $qry="SELECT name,type FROM glpi_computers WHERE os=".$ID." LIMIT 3;";
- $res = $this->query($qry);
- foreach($res as $val){
- $ret[$val['name']] = $val['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
- /* Operating systems
- Add a new operating system to the dropdown menus
- */
- function addOS($name)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE name='".$name."';");
- if(isset($tmp[0])){
- echo "such an entry already exists";
- return(false);
- }else{
- return($this->query("INSERT INTO glpi_dropdown_os (name) VALUES ('".$name."');"));
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Operating systems
- remove one OS entry
- */
- function removeOS_byID($id)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";");
- if(is_array($tmp[0])){
- return($this->query("DELETE FROM glpi_dropdown_os WHERE ID=".$id.";"));
- }else{
- echo "can't remove not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Operating systems
- Update existing OS entry
- */
- function updateOS($name,$id)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";");
- if(isset($tmp[0])){
- return($this->query("UPDATE glpi_dropdown_os SET name='".$name."' WHERE ID=".$id.";"));
- }else{
- echo "can't update not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* This returns all available glpi users
- */
- function getUsers()
- {
- if($this->is_connected){
- $ret = array();
- $tmp = ($this->query("SELECT * FROM glpi_users"));
- foreach($tmp as $user){
- $ret[$user['ID']]=$user['name'];
- }
- return($ret);
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* this function adds a new glpi user
- */
- function addUser($array,$dn)
- {
- if(!is_array($array)){
- echo "addUser: first paraeter must be an array";
- }elseif($this->is_connected){
- $array['name']=$dn;
- $atr = array("name","phone","email");
- $v = "";
- $a = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $a .= $at.", ";
- $v .= "'".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "addUser: no attributes given ";
- return(false);
- }else{
- $a = preg_replace("/, $/","",$a);
- $v = preg_replace("/, $/","",$v);
- return($this->query("INSERT INTO glpi_users (".$a.") VALUES (".$v.");"));
- }
-
- }else{
- echo "not connected";
- return(false);
- }
-
- }
-
- /* This function updates a glpi user
- with the given data
- */
- function updateUser($array,$dn)
- {
- if(!is_array($array)){
- echo "updateUser: first paraeter must be an array";
- }elseif($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_users WHERE name='".$dn."';");
- if(isset($tmp[0])){
-
- $atr = array("name","phone","email");
- $v = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $v .= " ".$at."='".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "UpdateUser: no attributes given ";
- return(false);
- }else{
- $v = preg_replace("/, $/","",$v);
- return($this->query("UPDATE glpi_users SET ".$v." WHERE name='".$dn."';"));
- }
- }else{
- echo "can't update not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
-
- }
-
- /* This function returns all available data
- from a specified dn
- */
- function getComputerInformations($name)
- {
- if($this->is_connected){
- $ret = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* This fucntions updates an already existing entry
- */
- function updateComputerInformations($array,$name)
- {
- if(!is_array($array)){
- echo "updateComputerInformations: first paraeter must be an array";
- }elseif($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
- if(isset($tmp[0])){
-
- $atr = array( "ID","name","serial","otherserial","contact","contact_num",
- "tech_num","comments","date_mod","os","location","domain","network",
- "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
- $v = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $v .= " ".$at."='".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "updateComputerInformations: no attributes given ";
- return(false);
- }else{
- $v = preg_replace("/, $/","",$v);
- return($this->query("UPDATE glpi_computers SET ".$v." WHERE name='".$name."';"));
- }
- }else{
- echo "can't update not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
-
- }
-
- /* This function adds a new inventory device (computer phone etc)
- */
- function addComputerInformations($array)
- {
- if(!is_array($array)){
- echo "updateComputerInformations: first paraeter must be an array";
- }elseif($this->is_connected){
- $atr = array( "ID","name","serial","otherserial","contact","contact_num",
- "tech_num","comments","date_mod","os","location","domain","network",
- "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
- $v = "";
- $a = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $a .= $at.", ";
- $v .= "'".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "updateComputerInformations: no attributes given ";
- return(false);
- }else{
- $a = preg_replace("/, $/","",$a);
- $v = preg_replace("/, $/","",$v);
- return($this->query("INSERT INTO glpi_computers (".$a.") VALUES (".$v.");"));
- }
-
- }else{
- echo "not connected";
- return(false);
- }
-
- }
-
- /* this functions checks if the given Device
- * already exists
- */
- function deviceExists($attr)
- {
- $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
- if($this->is_connected){
- $arr = array_flip($deviceMappingGOsaGlpi);
-
- $tbl_name = $arr[$attr['device_type']];
- if(!isset($attr['ID'])){
- return(false);
- }else{
- $qry = "SELECT * FROM ".$tbl_name." WHERE ID=".$attr['ID'].";";
- $res = $this->query($qry);
- if(count($res) != 0){
- return(true);
- }
- }
- }else{
- echo "not connected";
- return(false);
- }
-
- return(false);
- }
-
-
- /* Check if given device is used by some accounts
- * (helpfull to avoid removement of used devices)
- */
- function is_deviceUsed($item)
- {
- $deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
- $deviceMappingTableNameID = $this->deviceMappingTableNameID;
- if($this->is_connected){
- $tablename = $deviceMappingGOsaGlpi[$item['device_type']];
- $type = $item['device_type'];
-
- $ret = array();
-
- if($type=="monitor"){
- $str = "SELECT c.name FROM glpi_connect_wire as w, glpi_computers as c WHERE w.end1=".$item['ID']." AND w.end2 = c.ID AND w.type=4;";
- }else{
- $str = "SELECT c.name FROM glpi_computer_device as d, glpi_computers as c WHERE d.FK_computers=c.ID AND FK_device=".$item['ID']." AND device_type=".$deviceMappingTableNameID[$type]." ;";
- }
-
- $res = $this->query($str);
-
- foreach($res as $val){
- $ret[$val['name']] = $val['name'];
- }
-
- return($ret);//count($this->query($str)));
- }else{
- echo "not connected";
- return(false);
- }
-
- }
-
-
- /* This functions deletes a specified entry
- * from our device tables
- */
- function deleteDevice($attr)
- {
- $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
- if($this->is_connected){
- $arr = array_flip($deviceMappingGOsaGlpi);
-
- $device_type = $attr['device_type'];
- unset($attr['device_type']);
-
- $tbl_name = $arr[$device_type];
-
- $this->query("DELETE FROM ".$tbl_name." WHERE ID=".$attr['ID'].";");
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* This funtions updated an already existing device
- */
- function updateDevices($attr)
- {
- $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
- if($this->is_connected){
- $arr = array_flip($deviceMappingGOsaGlpi);
-
- $device_type = $attr['device_type'];
- unset($attr['device_type']);
-
- $tbl_name = $arr[$device_type];
-
- $str = "UPDATE ".$tbl_name." SET ";
- foreach($attr as $name => $value){
- $str.=$name."='".$value."', ";
- }
- $str = preg_replace("/, $/","",$str);
- $str .= " WHERE ID=".$attr['ID'].";";
- $this->query($str);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Returns all possible RAM types
- * like SDRAM , DIMM .....
- */
- function getRAMTypes()
- {
- if($this->is_connected){
- $ret = array();
- $tmp = ($this->query("SELECT * FROM glpi_dropdown_ram_type;"));
- foreach($tmp as $t){
- $ret[$t['ID']]=$t['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Returns all possible HDD connection types
- * like IDE SCSI ...
- */
- function getGlpiDeviceControlTypes()
- {
- if($this->is_connected){
- $ret = array();
- $tmp = ($this->query("SELECT * FROM glpi_dropdown_hdd_type;"));
- foreach($tmp as $t){
- $ret[$t['ID']]=$t['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Returns all possible gfx card connection types
- * like PCI-X PCI AGP ....
- */
- function getGlpiGfxControlTypes()
- {
- if($this->is_connected){
- $ret = array();
- $tmp = ($this->query("SELECT * FROM glpi_dropdown_hdd_type;"));
- foreach($tmp as $t){
- $ret[$t['ID']]=$t['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Devices
- Adds a new single device to our db
- */
- function addDevice($attr)
- {
- $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
- if($this->is_connected){
- $arr = array_flip($deviceMappingGOsaGlpi);
-
- $device_type = $attr['device_type'];
- unset($attr['device_type']);
-
- $tbl_name = $arr[$device_type];
- $v = "";
- $a = "";
- foreach($attr as $name => $value){
- $a .= $name.", ";
- $v .= "'".$value."', ";
- }
- if(empty($v)){
- echo "addDevice: no attributes given ";
- return(false);
- }else{
- $a = preg_replace("/, $/","",$a);
- $v = preg_replace("/, $/","",$v);
- return($this->query("INSERT INTO ".$tbl_name." (".$a.") VALUES (".$v.");"));
- }
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Return all available devices
- */
- function getDevices()
- {
- $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
- if($this->is_connected){
- $arr = $deviceMappingGOsaGlpi;
-
- $res = array();
- foreach($arr as $glpi => $gosa){
- $qry = "SELECT * FROM ".$glpi.";";
- $ret = $this->query($qry);
- foreach($ret as $id => $entry){
- $entry['device_type'] = $gosa;
-
- if(isset($entry['designation'])){
- $res[$entry['designation']."-".$gosa] = $entry;
- }else{
- $res[$entry['name']."-".$gosa] = $entry;
- }
- }
- }
- return($res);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* This function returns all used devices
- */
- function getUsedDevices($computerID)
- {
- $deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
- $deviceMappingTableNameID = $this->deviceMappingTableNameID;
-
- if($this->is_connected){
- $qry = "SELECT * FROM glpi_computer_device WHERE FK_computers=".$computerID.";";
- $res = $this->query($qry);
-
- $ret = array();
- foreach($deviceMappingGOsaGlpi as $GOsa => $glpi){
- $ret[$GOsa] = array();
- }
-
- $tbls = array_flip($deviceMappingTableNameID);
-
- foreach($res as $device){
- $devtype = $tbls[$device['device_type']];
- $tbl_name = $deviceMappingGOsaGlpi[$devtype];
- $qry = ("SELECT * FROM ".$tbl_name." WHERE ID=".$device['FK_device'].";");
- $res2 = $this->query($qry);
- if(count($res2)!=0){
- $ret[$devtype][$res2[0]['designation']]=$res2[0];
- }
-
- $qry = "SELECT * FROM glpi_connect_wire WHERE type=4 AND end2=".$computerID.";";
- $res2 = $this->query($qry);
- foreach($res2 as $monitor){
- $qry = "SELECT * FROM glpi_monitors WHERE ID=".$monitor['end1'].";";
- $res3 = $this->query($qry);
- foreach($res3 as $moni){
- $ret['monitor'][$moni['name']]=$moni;
- }
- }
-
-
-
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* This function removes all given devices from a computer, specified by $id
- In the next step all devices specified by devices will be added.
- */
- function addDevicesToComputer($devices, $id)
- {
- $deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
- $deviceMappingTableNameID = $this->deviceMappingTableNameID;
-
- if(($id == "" )||(!is_numeric($id))){
- return (false);
- }
- if($this->is_connected){
- $qry = "DELETE FROM glpi_computer_device WHERE FK_computers=".$id.";";
- $this->query($qry);
-
- foreach($devices as $type => $entries){
- foreach($entries as $entry){
- if($type=="monitor"){
- $str = "INSERT INTO glpi_connect_wire (end1,end2,type)
- VALUES (".$entry['ID'].",".$id.",4);";
- }else{
- $str = "INSERT INTO glpi_computer_device (device_type,FK_device,FK_computers)
- VALUES (".$deviceMappingTableNameID[$type].",".$entry['ID'].",".$id.");";
- }
- $this->query($str);
- }
- }
-
-
- }else{
- echo "not connected";
- return(false);
- }
-
- }
-
- function removeComputerInformations($name)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
- if(isset($tmp[0])){
- $id = $tmp[0]['ID'];
- $this->query("DELETE FROM glpi_connect_wire WHERE end2=".$id.";");
- $this->query("DELETE FROM glpi_computer_device WHERE FK_computers=".$id.";");
- return($this->query("DELETE FROM glpi_computers WHERE ID=".$id.";"));
- }else{
- echo "can't remove not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function is_connected()
- {
- return($this->is_connected);
- }
-
- function addAttachmentsToComputer($attr,$id)
- {
- if(($id == "" )||(!is_numeric($id))){
- return (false);
- }
- if($this->is_connected){
- $qry = "DELETE FROM glpi_doc_device WHERE (FK_device=".$id.") AND (device_type=1);";
- $this->query($qry);
-
- foreach($attr as $aid => $entry){
- $str = "INSERT INTO glpi_doc_device (FK_doc,FK_device,device_type,is_template)
- VALUES
- ($aid,$id,1,'0');";
- $this->query($str);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getAssignAttachments($id)
- {
-
- if($this->is_connected){
- $qry= "SELECT * FROM glpi_doc_device WHERE (device_type=1) AND (FK_device=".$id.");";
- $ret = $this->query($qry);
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function deleteAttachment($id)
- {
- if($this->is_connected){
- $qry = "DELETE FROM glpi_docs WHERE ID=".$id."";
- $this->query($qry);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getAttachments()
- {
- $ret = array();
- if($this->is_connected){
- $qry = "SELECT * FROM glpi_docs WHERE name!='';";
- $re = $this->query($qry);
-
- foreach($re as $entry){
- $ret[$entry['ID']]=$entry;
- }
-
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function saveAttachments($attrs,$id = -1)
- {
- if($this->is_connected){
- $atr = array("name","filename","rubrique","mime","date_mod","comment","deleted","link");
- $tmp = array();
- foreach($atr as $at){
- if(isset($attrs[$at])){
- $tmp[$at] = $attrs[$at];
- }
- }
- if(count($tmp)==0){
- return(false);
- }else{
-
- // Add
- if($id == -1){
- $str = "INSERT INTO glpi_docs ";
- $namen = "";
- $values= "";
- foreach($tmp as $name => $value){
- $namen .= $name.", ";
- if(is_numeric($value)){
- $values .= $value.", ";
- }else{
- $values .= "'".$value."', ";
- }
- }
- $values = preg_replace("/, $/","",$values);
- $namen = preg_replace("/, $/","",$namen);
- $str .= "(".$namen.") VALUES (".$values.");";
- }else{
- $str = "UPDATE glpi_docs SET ";
- foreach($tmp as $name => $value){
- $str .= $name."= ";
- if(is_numeric($value)){
- $str .= $value.", ";
- }else{
- $str .= "'".$value."', ";
- }
- }
- $str = preg_replace("/, $/","",$str);
- $str .= " WHERE ID=".$id.";";
- }
- $this->query($str);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
- /* Check if given attachment id is used in any Device
- ( - avoid removing of used attachments)
- */
- function is_attachmentUsed($id)
- {
- if($this->is_connected){
- $ret = array();
- $qry = "SELECT t.name FROM glpi_computers as t, glpi_doc_device WHERE t.ID = glpi_doc_device.FK_device AND FK_doc =".$id." LIMIT 3;";
- $res = $this->query($qry);
- foreach($res as $val){
- $ret[$val['name']] = $val['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
- /* Monitor handling
- */
- function getMonitors()
- {
- if($this->is_connected){
- $qry= "SELECT * FROM glpi_monitors;";
- return($this->query($qry));
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function updatedMonitor()
- {
- if($this->is_connected){
-// $qry= "SELECT * FROM glpi_monitors;";
-// return($this->query($qry));
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function addMonitor()
- {
- if($this->is_connected){
-// $qry= "SELECT * FROM glpi_monitors;";
-// return($this->query($qry));
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function removeMonitor($id)
- {
- if($this->is_connected){
- $qry= "DELETE FROM glpi_monitors WHERE ID=".$id.";";
- $this->query($qry);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getMonitorTypes()
- {
- if($this->is_connected){
- $qry= "SELECT * FROM glpi_type_monitors;";
- return($this->query($qry));
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getLocationTypes()
- {
- if($this->is_connected){
- $qry= "SELECT * FROM glpi_dropdown_locations;";
- return($this->query($qry));
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getStateTypes()
- {
- if($this->is_connected){
- $qry= "SELECT * FROM glpi_dropdown_state;";
- return($this->query($qry));
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
- /* Printer functions
- */
-
- /* is printer type used ?
- */
- function is_printerTypeUsed($id)
- {
- if($this->is_connected){
- $qry = "SELECT * FROM glpi_printers WHERE type=".$id.";";
- $res = $this->query( $qry);
- $ret =array();
- foreach($res as $entry){
- $ret[$entry['ID']] = $entry['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* This functions checks if the selected computer/network
- device is already available in the db
- */
- function is_printer_account($dn)
- {
- if(!$this->is_connected){
- $this->lasterror ="Can't query anything, if we aren't connected.";
- return(false);
- }else{
- $qry = "SELECT * FROM glpi_printers WHERE name='".$dn."';";
- $res = $this->query($qry);
- if(count($res)==0){
- return(false);
- }else{
- return(true);
- }
- }
- }
-
- /* This function returns all available data
- from a specified dn
- */
- function getPrinterInformations($name)
- {
- if($this->is_connected){
- $ret = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Get Printer attachments
- */
- function getAssignPrinterAttachments($id)
- {
-
- if($this->is_connected){
- $qry= "SELECT * FROM glpi_doc_device WHERE (device_type=3) AND (FK_device=".$id.");";
- $ret = $this->query($qry);
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Printer types
- Returns all defined printer types
- */
- function getPrinterTypes()
- {
- if($this->is_connected){
- $ret = array();
- $tmp = ($this->query("SELECT * FROM glpi_type_printers ORDER BY name; "));
- foreach($tmp as $t){
- $ret[$t['ID']]=$t['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Add pritner types
- Add one entry to the printer types
- */
- function addPrinterType($name)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_type_printers WHERE name='".$name."';");
- if(isset($tmp[0])){
- //echo "such an entry already exists";
- return(false);
- }else{
- return($this->query("INSERT INTO glpi_type_printers (name) VALUES ('".$name."');"));
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* remove printer types
- Remove one entry from the printer types (specified by ID=$id)
- */
- function removePrinterType($id)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_type_printers WHERE ID=".$id.";");
- if(isset($tmp[0])){
- return($this->query("DELETE FROM glpi_type_printers WHERE ID=".$id.";"));
- }else{
- echo "can't remove not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Update printer types
- Update a printer type
- */
- function updatePrinterType($name,$id)
- {
-
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_type_printers WHERE ID=".$id.";");
- if(isset($tmp[0])){
- return($this->query("UPDATE glpi_type_printers SET name='".$name."' WHERE ID=".$id.";"));
- }else{
- echo "can't update not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
- /* This fucntions updates an already existing entry
- */
- function updatePrinterInformations($array,$name)
- {
- if(!is_array($array)){
- echo "updatePrinterInformations: first paraeter must be an array";
- }elseif($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
- if(isset($tmp[0])){
-
- $atr = array( "ID","name","serial","otherserial","contact","contact_num",
- "tech_num","comments","date_mod","location","domain","network","ramSize","flags_serial","flags_par","flags_usb",
- "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
- $v = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $v .= " ".$at."='".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "updateSystemInformations: no attributes given ";
- return(false);
- }else{
- $v = preg_replace("/, $/","",$v);
- return($this->query("UPDATE glpi_printers SET ".$v." WHERE name='".$name."';"));
- }
- }else{
- echo "can't update not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
-
- }
-
- /* This function adds a new inventory settings for printers
- */
- function addPrinterInformations($array)
- {
- if(!is_array($array)){
- echo "updateComputerInformations: first paraeter must be an array";
- }elseif($this->is_connected){
- $atr = array( "ID","name","serial","otherserial","contact","contact_num",
- "tech_num","comments","date_mod","os","location","domain","network","ramSize","flags_serial","flags_par","flags_usb",
- "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
- $v = "";
- $a = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $a .= $at.", ";
- $v .= "'".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "updateComputerInformations: no attributes given ";
- return(false);
- }else{
- $a = preg_replace("/, $/","",$a);
- $v = preg_replace("/, $/","",$v);
- return($this->query("INSERT INTO glpi_printers (".$a.") VALUES (".$v.");"));
- }
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* add atachment to given printer */
- function addAttachmentsToPrinter($attr,$id)
- {
- if(($id == "" )||(!is_numeric($id))){
- return (false);
- }
- if($this->is_connected){
- $qry = "DELETE FROM glpi_doc_device WHERE (FK_device=".$id.") AND (device_type=3);";
- $this->query($qry);
-
- foreach($attr as $aid => $entry){
- $str = "INSERT INTO glpi_doc_device (FK_doc,FK_device,device_type,is_template)
- VALUES
- ($aid,$id,3,'0');";
- $this->query($str);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function removePrinterInformations($name)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
- if(isset($tmp[0])){
- $id = $tmp[0]['ID'];
-// $this->query("DELETE FROM glpi_connect_wire WHERE end2=".$id.";");
- $this->query("DELETE FROM glpi_doc_device WHERE FK_device=".$id." AND device_type=3;");
- return($this->query("DELETE FROM glpi_printers WHERE ID=".$id.";"));
- }else{
- echo "can't remove not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
- /* Cartridges
- */
- /* return all assigned cartridges */
- function getUsedCartridges($printerID)
- {
- if($this->is_connected){
- $ret = array();
- $qry = "SELECT
- c.date_use as date_use,
- c.ID as ID,
- t.ID as type_ID,
- t.name as name,
- c.FK_glpi_printers as FK_glpi_printers,
- d.name as type_name
- FROM
- glpi_dropdown_cartridge_type as d,
- glpi_cartridges as c,
- glpi_cartridges_type as t
- WHERE c.FK_glpi_cartridges_type = t.ID
- AND t.type = d.ID
- AND c.FK_glpi_printers = ".$printerID.";";
- $res = $this->query($qry);
- foreach($res as $entry){
- $ret[$entry['ID']] = $entry;
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* return all assigned cartridges */
- function getAvailableCartridgeTypes($printerTypeID)
- {
- if($this->is_connected){
- $ret = array();
- $qry= "
- SELECT
- ct.ID as cartridgeID,
- ct.name as cartridgeName,
- pt.ID as printerTypeID,
- pt.name as printerTypeName,
- ct.type as cartridgeTypeID,
- dt.name as cartridgeTypeName
- FROM
- glpi_type_printers as pt,
- glpi_cartridges_type as ct,
- glpi_dropdown_cartridge_type as dt,
- glpi_cartridges_assoc as ac
- WHERE
- ac.FK_glpi_type_printer = pt.ID
- AND ac.FK_glpi_cartridges_type = ct.ID
- AND ct.type=dt.ID
- AND pt.ID=".$printerTypeID.";";
- $res = $this->query($qry);
- foreach($res as $entry){
- $ret[$entry['cartridgeID']] = $entry;
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function removeCartridgeFromPrinter($cartridgeID)
- {
- if($this->is_connected){
- $qry = "DELETE FROM glpi_cartridges WHERE ID=".$cartridgeID.";";
- return($this->query($qry));
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function addCartridgeFromPrinter($printerID,$cartridgeID)
- {
- if($this->is_connected){
- $qry ="INSERT INTO
- glpi_cartridges (FK_glpi_cartridges_type,FK_glpi_printers,date_in,date_use)
- VALUES
- (".$cartridgeID.",".$printerID.",'".date("Y-m-d")."','".date("Y-m-d")."');";
- return($this->query($qry));
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function is_cartridgeTypeUsed($id){
- if($this->is_connected){
- $qry = "SELECT p.ID,p.name as name FROM glpi_cartridges as c,glpi_printers as p WHERE p.ID=c.FK_glpi_printers AND c.FK_glpi_cartridges_type=".$id.";";
- $res = $this->query($qry);
- $ret =array();
- foreach($res as $entry){
- $ret[$entry['ID']] = $entry['name'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getCartridgeTypeInformations($id = "all"){
- if($this->is_connected){
- $ret = array();
- if($id != "all"){
- $qry = "SELECT * FROM glpi_cartridges_type WHERE ID = ".$id.";";
- }else{
- $qry = "SELECT * FROM glpi_cartridges_type;";
- }
-
- $res = ($this->query($qry));
- foreach($res as $entry){
- $ret[$entry['ID']] = $entry;
- }
- return($ret);
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getCartridgeTypes(){
- if($this->is_connected){
- $ret = array();
- $qry = "SELECT * FROM glpi_dropdown_cartridge_type;";
- $res = ($this->query($qry));
- foreach($res as $entry){
- $ret[$entry['ID']] = $entry['name'];
- }
- return($ret);
-
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
-
- /* check if given manufacturer ID ist still in use.
- The problem is, that nearly every table uses manufacturers ....
- */
- function is_manufacturerUsed($id)
- {
- if($this->is_connected){
- $tables = array();
- foreach($this->deviceMappingGOsaGlpi as $entry => $table){
- $tables[] = $entry;
- }
- $tables[] ="glpi_computers";
- $tables[] ="glpi_cartridges_type";
- $ret = array();
- $i = 3;
- foreach($tables as $tbl){
- if($i <= 0 ) continue;
- $qry = "SELECT * FROM ".$tbl." WHERE FK_glpi_enterprise = ".$id.";";
- $res = $this->query($qry);
- foreach($res as $entry){
- if($i <= 0 ) continue;
- if(isset($entry['designation'])){
- $entry['name'] = $entry['designation'];
- }
- $i --;
- $ret[] = $entry['name'];
- }
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Manufacturer
- Updates already existing manufacturer
- */
- function Add_UpdateCatrigdeType($array,$array_printer_types)
- {
- if(!is_array($array)){
- echo "Add_UpdateCatrigdeType: first paraeter must be an array";
- }elseif($this->is_connected){
-
-
- $atr = array("name","ref","location","type","FK_glpi_enterprise","tech_num","deleted","comments","alarm");
-
- /* Entry was edited */
- if($array['ID']>0){
- $qry = "DELETE FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type=".$array['ID'].";";
-
- $v = "";
- foreach($atr as $at){
- if(isset($array[$at])){
- $v .= " ".$at."='".$array[$at]."', ";
- }
- }
- if(empty($v)){
- echo "Add_UpdateCatrigdeType: no attributes given ";
- return(false);
- }else{
- $v = preg_replace("/, $/","",$v);
- $qry = "UPDATE glpi_cartridges_type SET ".$v." WHERE ID='".$array['ID']."';";
- $this->query($qry);
- }
- }else{
-
- /* skip if name is in use*/
- $qry = "SELECT * FROM glpi_cartridges_type WHERE name='".$array['name']."';";
- if(count($this->query($qry))){
- return;
- }
-
- $str = "INSERT INTO glpi_cartridges_type ";
- $namen = "";
- $values= "";
- foreach($array as $name => $value){
- $namen .= $name.", ";
- if(is_numeric($value)){
- $values .= $value.", ";
- }else{
- $values .= "'".$value."', ";
- }
- }
- $values = preg_replace("/, $/","",$values);
- $namen = preg_replace("/, $/","",$namen);
- $str .= "(".$namen.") VALUES (".$values.");";
- $this->query($str);
- $IDs = $this->query("SELECT ID FROM glpi_cartridges_type WHERE name='".$array['name']."';");
- if(count($IDs) > 1){
- echo "internal db error";
- return;
- }
- $array['ID'] = $IDs[0]['ID'];
- }
-
- foreach($array_printer_types as $id){
- $qry = "INSERT INTO glpi_cartridges_assoc
- (FK_glpi_cartridges_type,FK_glpi_type_printer)
- VALUES
- (".$array['ID'].",".$id.")";
-
- $this->query($qry);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getSupportedPrinterTypeIDsForCartridge($cid)
- {
- if($this->is_connected){
- $ret = array();
- $qry = "SELECT FK_glpi_type_printer FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type = ".$cid.";";
- $res = $this->query($qry);
-
- foreach($res as $entry => $value){
- $ret[$value['FK_glpi_type_printer']] = $value['FK_glpi_type_printer'];
- }
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function removeCartridgeType($id){
- if($this->is_connected){
- $qry = "DELETE FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type=".$id.";";
- $this->query($qry);
- $qry = "DELETE FROM glpi_cartridges_type WHERE ID=".$id.";";
- return($this->query($qry));
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getCartridgesWhichUseThisType($id)
- {
- if($this->is_connected){
- $qry = "SELECT * FROM glpi_cartridges WHERE FK_glpi_cartridges_type=".$id.";";
- $ret = $this->query($qry);
- return($ret);
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-
- /* Add pritner types
- Add one entry to the cartridgeType types
- */
- function addCartridgeDropdownType($name)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE name='".$name."';");
- if(isset($tmp[0])){
- //echo "such an entry already exists";
- return(false);
- }else{
- return($this->query("INSERT INTO glpi_dropdown_cartridge_type (name) VALUES ('".$name."');"));
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* remove cartridgeType types
- Remove one entry from the cartridgeType types (specified by ID=$id)
- */
- function removeCartridgeDropdownType($id)
- {
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";");
- if(isset($tmp[0])){
- return($this->query("DELETE FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";"));
- }else{
- echo "can't remove not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- /* Update cartridgeType
- Update a cartridgeType
- */
- function updateCartridgeDropdownType($name,$id)
- {
-
- if($this->is_connected){
- $tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";");
- if(isset($tmp[0])){
- return($this->query("UPDATE glpi_dropdown_cartridge_type SET name='".$name."' WHERE ID=".$id.";"));
- }else{
- echo "can't update not existing entry";
- return(false);
- }
- }else{
- echo "not connected";
- return(false);
- }
- }
-
- function getUsedDropdownTypes($id=false)
- {
- if($this->is_connected){
- if($id){
- $qry = "SELECT distinct(type) FROM glpi_cartridges_type WHERE type = ".$id.";";
- }else{
- $qry = "SELECT distinct(type) FROM glpi_cartridges_type;";
- }
- return($this->query($qry));
- }else{
- echo "not connected";
- return(false);
- }
- }
-
-}
-//$s = new glpiDB("vserver-01","glpi","tester","glpi");
-//print_r($s->query("SELECT * FROM glpi_computers"));
-//$s->getComputerInformations("1 OR (c.ID<10000)");
-?>
index 6d437276bd161c1bf2739ffab81300d60b11ef88..a8e6a4bb1d09146bd933789b73e7218bf9f92109 100644 (file)
"MultiSelectWindow" => "include/class_MultiSelectWindow.inc",
"config" => "include/class_config.inc",
"SnapShotDialog" => "include/class_SnapShotDialog.inc",
- "dhcpPlugin" => "include/class_dhcpPlugin.inc",
"passwordMethod" => "include/class_password-methods.inc",
"Print_a_class" => "include/functions_debug.inc",
"LDAP" => "include/class_ldap.inc",
"dhcpGroup" => "plugins/admin/systems/services/dhcp/class_dhcpGroup.inc",
"dhcpHost" => "plugins/admin/systems/services/dhcp/class_dhcpHost.inc",
"dhcpNewSectionDialog" => "plugins/admin/systems/services/dhcp/class_dhcpNewSectionDialog.inc",
+ "dhcpPlugin" => "plugins/admin/systems/services/dhcp/class_dhcpPlugin.inc",
"dhcpService" => "plugins/admin/systems/services/dhcp/class_dhcpService.inc",
"servdhcp" => "plugins/admin/systems/services/dhcp/class_servDHCP.inc",
"ServiceAddDialog" => "plugins/admin/systems/services/class_ServiceAddDialog.inc",
diff --git a/gosa-core/include/class_opengw.inc b/gosa-core/include/class_opengw.inc
+++ /dev/null
@@ -1,547 +0,0 @@
-<?php
-
-require_once("class_pgsql_opengw.inc");
-
-class ogw{
- var $info;
- var $ogo;
-
- var $validLocationTeam;
- var $validTemplateUser;
- var $validTeams;
-
-
- var $InfoOK = false;
-
- var $MUST = array("name","login","template_user_id");
-
- var $MAY = array( "salutation","firstname","description","degree",
- "birthday","sex","street","zip","country","zipcity",
- "state","name1","value_string","number","db_status",
- "object_version","is_locked","LocationTeamID","TeamIDis","password");
-
- var $LastError = "";
- var $option = "";
- var $connected = false;
-
- function ogw($username,$password,$host,$db)
- {
- $this->ogo = new pgre_sql($username,$password,$host,$db);
-
- if($this->ogo->is_connected){
- $this->validLocationTeam = $this->ogo->GetLocationTeam();
- $this->validTemplateUser = $this->ogo->GetTemplateUser();
- $this->validTeams = $this->ogo->GetTeams();
- $this->connected = true;
- }else{
- $this->validLocationTeam = array();//$this->ogo->GetLocationTeam();
- $this->validTemplateUser = array();//$this->ogo->GetTemplateUser();
- $this->validTeams = array();//$this->ogo->GetTeams();
- $this->connected = false;
- }
- }
-
- function SetInfos($infos)
- {
- if(isset($infos['name'])) {
- $infos['name1'] = $infos['name'];
- }
- $this->info = $infos;
- }
-
- function GetInfos($uid)
- {
- $ret = array();
- $qry = "SELECT is_person,is_account,is_intra_account,is_extra_account,
- number,owner_id,object_version,company_id,template_user_id,is_locked,
- name,firstname,description,salutation,login,degree,birthday,sex
- FROM person WHERE login='".$uid."';";
- $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
- $ret = $res[0];
-
- $qry = "SELECT street,zip,zipcity,country,state FROM address WHERE company_id = ".$ret['company_id']." limit 1;";
- $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
- $ret = array_merge($ret,$res[0]);
-
- $qry = "SELECT company_id FROM company_assignment
- WHERE (sub_company_id=".$ret['company_id'].")
- AND company_id IN
- (SELECT company_id FROM team WHERE (is_team=1)
- AND
- company_id NOT IN (SELECT company_id FROM team WHERE is_location_team=1));";
- $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
- if(is_array($res)){
- foreach($res as $r){
- $ret['TeamIDis'][]=$r['company_id'];
- }
- }else{
- $ret['TeamIDis']=array();
- }
-
- $qry = "SELECT value_string from company_value WHERE company_id=".$ret['company_id'].";";
- $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
- $ret = array_merge($ret,$res[0]);
-
- $qry ="SELECT company_id FROM company_assignment
- WHERE (sub_company_id=".$ret['company_id'].")
- AND company_id IN (SELECT company_id FROM team WHERE (is_location_team=1));";
- $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
- $ret['LocationTeamID'] = $res[0]['company_id'];
-
- return($ret);
- }
-
- function Perform($option)
- {
- if(!in_array($option,array("ADD","EDIT","REMOVE"))){
- $this->LastError = sprintf("Option '%s' is not allowed, possible options are 'ADD' 'EDIT' 'REMOVE'.",$option);
- return(false);
- }else{
- $this->option = $option;
- if(($this->option == "EDIT")||($this->option=="ADD")){
-
- /* Static variables */
- if(!isset($this->info['is_person'])){
- $this->info['is_person'] = 1;
- }
-
- if(!isset($this->is_account)){
- $this->info['is_account'] = 1;
- }
-
- if(!isset($this->info['is_intra_account'])){
- $this->info['is_intra_account'] = 1;
- }
-
- if(!isset($this->info['is_extra_account'])){
- $this->info['is_extra_account'] = 0;
- }
-
- if(!isset($this->info['owner_id'])){
- $this->info['owner_id'] = 10000;
- }
-
- if(!isset($this->info['is_team'])){
- $this->info['is_team'] = 0;
- }
-
- $this->InfoOK = $this->checkInfos();
-
- if($this->InfoOK){
- $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
- $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
-
- if($this->option == "ADD"){
- if($this->CheckExistence()){
- $this->LastError="Can't add entry already exists.";
- return(false);
- }else{
- $this->info['db_status'] = "inserted";
- $this->info['object_version'] = 1;
- return($this->ADD());
- }
- }else{
- if(!$this->CheckExistence()){
- $this->LastError="Can't edit entry, entry doesn't exists.";
- return(false);
- }else{
- $this->info['db_status'] = "updated";
- $this->info['object_version'] = $ist[0]['object_version']++;
- return($this->EDIT());
- }
- }
- }else{
- return($this->InfoOK);
- }
- }
- if($this->option == "REMOVE"){
-
- if((!isset($this->info['login']))||(empty($this->info['login']))){
- $this->LastError = "Require login to detect existence";
- return(false);
- }else{
-
- if($this->CheckExistence()){
- return($this->REMOVE());
- }else{
- $this->LastError="Can't remove non existing entry";
- return(false);
- }
- }
- }
- }
- }
-
- function CheckExistence()
- {
- /* Check if thios entry already exists */
- $qry = "SELECT login,name FROM person WHERE login='".$this->info['login']."';";
- $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
- if($ist){
- return(true);
- }else{
- return(false);
- }
- }
-
- function checkInfos()
- {
- foreach($this->MUST as $name){
- if((!isset($this->info[$name]))||(empty($this->info[$name]))){
- $this->LastError = sprintf("Must attribute '%s' wasn't set.",$name);
- return(false);
- }
- }
-
- foreach($this->MAY as $name){
- if((!isset($this->info[$name]))||(empty($this->info[$name]))){
- $this->info[$name] = false;
- }
- }
-
- $tmp = array(false,"",0);
- foreach($this->validLocationTeam as $id){
- $tmp[]= $id['company_id'];
- }
- if(!in_array($this->info['LocationTeamID'],$tmp)){
- $this->LastError = "Given 'Location Team' is invalid.";
- return(false);
- }
-
- $tmp = array();
- foreach($this->validTemplateUser as $id){
- $tmp[]= $id['company_id'];
- }
- if(!in_array($this->info['template_user_id'],$tmp)){
- $this->LastError = "Given 'Template User ID' is invalid.";
- return(false);
- }
-
-
- $tmp = array();
- foreach($this->validTeams as $id){
- $tmp[]= $id['company_id'];
- }
- if(is_array($this->info['TeamIDis'])){
- foreach($this->info['TeamIDis'] as $id){
- if(!in_array($id,$tmp)){
- $this->LastError = sprintf("Given 'Team ID':%s is invalid.",$id);
- return(false);
- }
- }
- }
- return(true);
- }
-
- function REMOVE()
- {
- $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
- $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
- if((!$ist)||(!isset($ist[0]['company_id']))||($ist[0]['company_id']<=0)){
- $this->LastError(sprintf("Can't get company id for login %s",$this->info['login']));
- return(false);
- }else{
-
- $company_id = $ist[0]['company_id'];
-
- $qry = "UPDATE person SET login='SKY".$company_id.$this->info['login']."', is_account=0, is_intra_account=0 WHERE company_id=".$company_id.";";
- $this->ogo->Query($qry);
- /*
- $this->ogo->Query("DELETE FROM telephone WHERE company_id=".$company_id.";");
- $this->ogo->Query("DELETE FROM address WHERE company_id=".$company_id.";");
- $this->ogo->Query("DELETE FROM company_info WHERE company_id=".$company_id.";");
- $this->ogo->Query("DELETE FROM company_value WHERE company_id=".$company_id.";");
- $this->ogo->Query("DELETE FROM company_assignment WHERE sub_company_id=".$company_id.";");
- $this->ogo->Query("DELETE FROM person WHERE company_id=".$company_id.";");
- $this->ogo->Query("DELETE FROM staff WHERE company_id=".$company_id.";");
- */
- return(true);
- }
- }
-
- function ADD()
- {
- /*
- Entry settings for personm table
- */
- $arr = array( "company_id","object_version","owner_id","template_user_id",
- "is_person","is_account","is_intra_account","is_extra_account",
- "number","description","is_locked","login","name","name","firstname",
- "salutation","degree","birthday","sex","db_status","password");
- $this->info['company_id'] = $this->ogo->gen_id();
- $this->info['userID'] = "OGo".$this->info['company_id'];
- foreach($arr as $attr){
- if($attr == "number"){
- $add_user[$attr] = $this->info['userID'];
- }else{
- $add_user[$attr] = $this->info[$attr];
- }
- }
- $QUERY[] = gen_syntax($add_user,"person","ADD",false);
-
-
- /*
- Entry for staff table
- */
- $arr = array("staff_id","company_id","description","login","is_team","is_account","db_status");
- $this->info['staff_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_staff[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_staff,"staff","ADD",false);
-
-
- /*
- Create entries for company nfo
- */
- $arr = array("company_info_id","company_id","db_status");
- $this->info['company_info_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_company_info[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_company_info,"company_info","ADD",false);
-
-
- /*
- Create entries for company value
- */
- $arr = array("db_status","value_string","attribute","company_id","company_value_id");
- $this->info['attribute'] = "email1";
- $this->info['company_value_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_company_value[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_company_value,"company_value","ADD",false);
-
-
- /*
- address entries
- */
- $arr = array("company_id","address_id","street","zip","country","zipcity","state","db_status","name1","type");
- foreach(array("private","mailing","location") as $type){
-
- $this->info['address_id'] = $this->ogo->gen_id();
- $this->info['type'] = $type;
- foreach($arr as $attr){
- $add_address[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_address,"address","ADD",false);
- }
-
-
- /*
- telephone entries
- */
- $arr = array("telephone_id","object_version","company_id","number","type","db_status");
- foreach(array("01_tel","02_tel","03_tel_funk","05_tel_private","10_fax","fax_private") as $type){
- $this->info['type'] = $type;
- $this->info['telephone_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_telephone[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_telephone,"telephone","ADD",false);
- }
-
- /*
- company_assignment entries (Location Team)
- */
- $this->info['old_company_id'] = $this->info['company_id'];
- $this->info['sub_company_id'] = $this->info['old_company_id'];
-
- $this->info['company_assignment_id']= $this->ogo->gen_id();
- $this->info['company_id'] = $this->info['LocationTeamID'];
- $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
- foreach($arr as $attr){
- $add_company_assignment[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
-
-
- /*
- company_assignment entries (Teams)
- */
- $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
- foreach($this->info['TeamIDis'] as $TeamID){
-
- $this->info['company_id'] = $TeamID;
- $this->info['sub_company_id'] = $this->info['old_company_id'];
- $this->info['company_assignment_id']= $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_company_assignment[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
- }
-
- $remove_all = false;
- foreach($QUERY as $q ){
- if(!$this->ogo->Query($q)){
- $remove_all = true;
- break;
- }
- }
-
- if($remove_all== true){
- $this->ogo->Query("DELETE FROM telephone WHERE company_id=".$this->info['company_id'].";");
- $this->ogo->Query("DELETE FROM address WHERE company_id=".$this->info['company_id'].";");
- $this->ogo->Query("DELETE FROM company_assignment WHERE company_id=".$this->info['company_id'].";");
- $this->ogo->Query("DELETE FROM company_info WHERE company_id=".$this->info['company_id'].";");
- $this->ogo->Query("DELETE FROM company_value WHERE company_id=".$this->info['company_id'].";");
- $this->ogo->Query("DELETE FROM staff WHERE company_id=".$this->info['company_id'].";");
- $this->ogo->Query("DELETE FROM person WHERE company_id=".$this->info['company_id'].";");
- $this->LastError="Query failed, removed all added entries";
- return(false);
- }
- return(true);
- }
-
-
- function EDIT()
- {
- $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
- $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
- /*
- Entry settings for personm table
- */
- $arr = array( "company_id","object_version","owner_id",
- "template_user_id","is_person","is_account","is_intra_account",
- "is_extra_account","number","description","is_locked","login","name",
- "firstname","salutation","degree","birthday","sex","db_status","password");
- $this->info['company_id'] = $ist[0]['company_id'];
- $this->info['userID'] = "OGo".$this->info['company_id'];
- foreach($arr as $attr){
- if($attr == "number"){
- $add_user[$attr] = $this->info['userID'];
- }else{
- $add_user[$attr] = $this->info[$attr];
- }
- }
- $QUERY[] = gen_syntax($add_user,"person","EDIT",$ist);
-
-
- /*
- Entry for staff table
- */
- $arr = array("staff_id","company_id","description","login","is_team","is_account","db_status");
- $this->info['staff_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_staff[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_staff,"staff","EDIT",$ist);
-
-
- /*
- Create entries for company nfo
- */
- $arr = array("company_info_id","company_id","db_status");
- $this->info['company_info_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_company_info[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_company_info,"company_info","EDIT",$ist);
-
-
- /*
- Create entries for company value
- */
- $QUERY[] = "DELETE FROM company_value WHERE company_id=".$ist[0]['company_id']." AND attribute='mail1';";
- $arr = array("db_status","value_string","attribute","company_id","company_value_id");
- $this->info['attribute'] = "email1";
- $this->info['company_value_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_company_value[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_company_value,"company_value","ADD",false);
-
-
- /*
- address entries
- */
- $QUERY[] = "DELETE FROM address WHERE company_id=".$ist[0]['company_id'].";";
- $this->info['company_id'] = $ist[0]['company_id'];
- $arr = array("company_id","address_id","street","zip","country","zipcity","state","db_status","name1","type");
- foreach(array("private","mailing","location") as $type){
- $this->info['type'] = $type;
- $this->info['address_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_address[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_address,"address","ADD",false);
- }
-
-
- /*
- telephone entries
- */
- $QUERY[] = "DELETE FROM telephone WHERE company_id=".$ist[0]['company_id'].";";
- $this->info['company_id'] = $ist[0]['company_id'];
- $arr = array("telephone_id","object_version","company_id","number","type","db_status");
- foreach(array("01_tel","02_tel","03_tel_funk","05_tel_private","10_fax","fax_private") as $type){
- $this->info['type'] = $type;
- $this->info['telephone_id'] = $this->ogo->gen_id();
- foreach($arr as $attr){
- $add_telephone[$attr] = $this->info[$attr];
- }
-
- $QUERY[] = gen_syntax($add_telephone,"telephone","ADD",false);
- }
-
-
- /*
- company_assignment entries (Location Team)
- */
- $this->info['old_company_id'] = $this->info['company_id'];
-
- /* First remove location team */
- $QUERY[] = "DELETE FROM company_assignment WHERE (sub_company_id=".$ist[0]['company_id'].") AND
- company_id in (SELECT company_id FROM team WHERE is_location_team=1);";
-
- $this->info['sub_company_id'] = $ist[0]['company_id'];
- $this->info['company_assignment_id']= $this->ogo->gen_id();
- $this->info['company_id'] = $this->info['LocationTeamID'];
- $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
- foreach($arr as $attr){
- $add_company_assignment[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
-
-
- /*
- company_assignment entries (Teams)
- */
- /* First remove location team */
- $QUERY[] = "DELETE FROM company_assignment
- WHERE
- (sub_company_id=".$ist[0]['company_id'].")
- AND
- company_id IN
- (SELECT company_id FROM team WHERE (is_team=1) AND company_id NOT IN
- (SELECT company_id FROM team WHERE is_location_team=1));";
-
- $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
-
- if(is_array($this->info['TeamIDis'])){
- foreach($this->info['TeamIDis'] as $TeamID){
- $this->info['company_id'] = $TeamID;
- $this->info['sub_company_id'] = $ist[0]['company_id'];
- $this->info['company_assignment_id']= $this->ogo->gen_id();
- $add_company_assignment = array();
- foreach($arr as $attr){
- $add_company_assignment[$attr] = $this->info[$attr];
- }
- $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
- }
- }
- $remove_all = false;
-
- foreach($QUERY as $q ){
- if(!$this->ogo-> Query($q)){
- print $q;
- $remove_all = true;
- break;
- }
- }
- }
-}
-
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-core/include/class_password-methods.inc b/gosa-core/include/class_password-methods.inc
+++ /dev/null
@@ -1,131 +0,0 @@
-<?php
-/*
- This code is part of GOsa (https://gosa.gonicus.de)
- Copyright (C) 2004 Cajus Pollmeier
-
- This program 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.
-
- This program 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 this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-
-class passwordMethod
-{
- var $config = false;
- var $attrs= array();
-
- // Konstructor
- function passwordMethod($config)
- {
- }
-
-
- function get_hash_name()
- {
- }
-
- // Loads Methods in annother way as get_available_methods do, (For setup ..)
- // and loads them,.
- function get_available_methods_if_not_loaded($path_to_load="../include")
- {
- $oh = opendir($path_to_load);
- $i = 0;
- $ret = false;
- while ($file = readdir($oh)) {
- $one = strtolower($file);
- if((strstr($one,"class_password-methods-" ))&&($one[0]!=".")){
- require_once($file);
- }
- }
- return(passwordMethod::get_available_methods());
- }
-
-
-
- // Crypts a single string, with given Method
- function crypt_single_str($string,$method)
- {
- $available = passwordMethod::get_available_methods();
- if(!is_array($available))
- {
- $available = passwordMethod::get_available_methods_if_not_loaded();
- }
-
- $test = new $available[$method](false);
- $newpass = $test->generate_hash($string);
- return( $newpass);
- }
-
-
- // this function returns all loaded classes for password encryption
- static function get_available_methods()
- {
- global $class_mapping, $config;
- $ret =false;
- $i =0;
- foreach($class_mapping as $class => $path) {
- if(preg_match('/passwordMethod/i', $class) && !preg_match("/^passwordMethod$/i", $class)){
- $name = preg_replace ("/passwordMethod/i", "", $class);
- $test = new $class($config);
- if($test->is_available()) {
- $plugname= $test->get_hash_name();
- $ret['name'][$i]= $plugname;
- $ret['class'][$i]=$class;
- $ret[$i]['name']= $plugname;
- $ret[$i]['class']= $class;
- $ret[$plugname]=$class;
- $i++;
- }
- }
- }
- return($ret);
- }
-
-
- // Method to let password backends remove additional information besides
- // the userPassword attribute
- function remove_from_parent()
- {
- }
-
-
- // Method to let passwords backends manage additional information
- // besides the userAttribute entry
- function set_password($password)
- {
- }
-
-
- // Return true if this password method provides a configuration dialog
- function is_configurable()
- {
- return FALSE;
- }
-
-
- // Provide a subdialog to configure a password method
- function configure()
- {
- return "";
- }
-
-
- // Save information to LDAP
- function save($dn)
- {
- }
-
-
-}
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-core/include/class_pgsql_opengw.inc b/gosa-core/include/class_pgsql_opengw.inc
+++ /dev/null
@@ -1,160 +0,0 @@
-<?php
-
-class pgre_sql{
-
- var $handle;
- var $query_log;
- var $user;
- var $server;
- var $db;
- var $pwd;
- var $is_connected = false;
-
- function pgre_sql($user,$pwd,$server,$db)
- {
- $this->user = $user;
- $this->pwd = $pwd;
- $this->server = $server;
- $this->db = $db;
-
- if($this->_connect()){
- $this->is_connected = true;
- }else{
- $this->is_connected = false;
- }
- }
-
- function _connect()
- {
- error_reporting(E_ALL | E_STRICT);
- if(is_callable("pg_connect")){
- if(!empty($this->pwd)){
- $this->handle = @pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user);
- }else{
- $this->handle = @pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user." password=".$this->pwd);
- }
- if(!$this->handle){
- $this->handle = false;
- }
- }else{
- $this->handle = false;
- }
- return($this->handle);
- }
-
- function Query($a_query)
- {
- if(is_array($a_query)){
- foreach($a_query as $nr => $query){
- return($this->_query($query));
- }
- }else{
- return($this->_query($a_query));
- }
- }
-
- function _query($query)
- {
- return(pg_query($this->handle,$query));
- }
-
- function FetchAllRows($res)
- {
- return(pg_fetch_all($res)) ;
- }
-
- function gen_id()
- {
- $tmp = $this->_query("select nextval('key_generator');");
- $tmp = ($this->FetchAllRows($tmp));
- return($tmp[0]['nextval']);
- }
-
-
- function GetTemplateUser(){
- $data = array();
- $qry = "SELECT description,name,company_id FROM company WHERE is_template_user=1;";
- $res = $this->_query($qry);
- $tmp = $this->FetchAllRows($res);
- foreach($tmp as $attr){
- $data[$attr['name']] = $attr;
- }
- return $data;
- }
- function GetLocationTeam(){
- $data = array();
- $qry = "SELECT description,name,company_id FROM team WHERE is_location_team=1;";
- $res = $this->_query($qry);
- $tmp = $this->FetchAllRows($res);
- if(is_array($tmp)){
- foreach($tmp as $attr){
- $data[$attr['description']] = $attr;
- }
- }
- return $data;
- }
- function GetTeams(){
- $data = array();
- $qry = "SELECT description,name,company_id FROM team
- WHERE (is_team=1) AND company_id
- NOT IN (SELECT company_id FROM company WHERE is_location_team=1);";
- $res = $this->_query($qry);
- $tmp = $this->FetchAllRows($res);
- foreach($tmp as $attr){
- $data[$attr['description']] = $attr;
- }
- return $data;
- }
-}
-
-
-function gen_syntax($array,$tablename,$act,$ist)
-{
- if($act == "EDIT"){
- $str = "UPDATE ".$tablename." SET ";
- $company_id = $ist[0]['company_id'];
-
- foreach($array as $name => $value){
- if((empty($value))&&(!preg_match("/^is_/i",$name))) continue;
-
- if((empty($value))&&(preg_match("/^is_/i",$name))){
- $value= 0;
- }
-
- if(!is_numeric($value)){
- $str.= " ".$name."='".$value."', ";
- }else{
- $str.= " ".$name."=".$value.", ";
- }
- }
- $str = preg_replace("/, $/","",$str);
- $str .= " WHERE company_id=".$company_id.";\n";
- return $str;
- }
- if($act == "ADD"){
- $str = "INSERT into ".$tablename." (";
- $attrs = "";
- $values = "";
- foreach($array as $name => $attribute){
- if((empty($attribute))&&(!preg_match("/^is_/i",$name))) continue;
-
- if((empty($attribute))&&(preg_match("/^is_/i",$name))){
- $attribute= 0;
- }
-
- if(is_numeric($attribute)){
- $attrs .= $name.", ";
- $values .= $attribute.", ";
- }else{
- $attrs .= $name.", ";
- $values .= "'".$attribute."', ";
- }
- }
- $attrs = preg_replace("/, $/","",$attrs);
- $values= preg_replace("/, $/","",$values);
- $str .= $attrs." ) \nVALUES\n (".$values.");\n";
- return $str;
- }
-}
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-core/include/class_ppdManager.inc b/gosa-core/include/class_ppdManager.inc
+++ /dev/null
@@ -1,356 +0,0 @@
-<?php
-
-class ppdManager
-{
- var $path= "";
- var $cachedList= array();
- var $timestamps = array();
-
- function ppdManager($path)
- {
- if(is_dir($path)){
- $this->path= $path;
- }else{
- msg_dialog::display(_("PPD manager error"), sprintf(_("The specified path '%s' does not exist."),$path), ERROR_DIALOG);
- return (false);
- }
- }
-
-
- function findPPD($path)
- {
- $list= array();
- $currentDir= getcwd();
-
- $dh = opendir($path);
- while(false !== ($file = readdir($dh))){
-
- /* Skip well known files */
- if( $file == '.' || $file == '..'){
- continue;
- }
-
- /* Recurse through all "common" directories */
- if(is_dir($path.'/'.$file)){
- $list= array_merge($list, $this->findPPD($path.'/'.$file));
- continue;
- }
-
- /* Check for PPD extension */
- if (preg_match('/\.ppd$/i', $file)){
- $list[]= $path.'/'.$file;
- }
- }
-
- closedir($dh);
- chdir ($currentDir);
- return ($list);
- }
-
-
- function updateAttribute($file, $section, $attribute, $value)
- {
- $fsection= false;
- $fattribute= false;
- $section= preg_replace('/^\*/', '', $section);
- $attribute= preg_replace('/^\*/', '', $attribute);
-
- $rp= @fopen($file, "r");
- $wp= @fopen("$file.tmp", "w");
-
-
-
- while (!feof($rp)){
- $lines[]= fgets($rp, 1024);
- }
-
- $ret = "";
- $done =false;
- foreach($lines as $nr => $line){
-
- if (preg_match("/\*OpenGroup:*\s+\**$section\/*/", $line)){
- $fsection= true;
- $ret .=$line;
- continue;
- }
-
- /* Change model name .. */
- if ((preg_match("/^\*".$attribute.":*\s+/",$line)) && ($attribute == "ModelName")){
- $line= "*$attribute: \"$value\"\n";
- $done =true;
- }
-
- if (($fsection) && ($section != "NO_SECTION")){
- if (preg_match("/^\*CloseGroup:*\s+\**$section\/*/", $line)){
- $fsection= false;
- $ret .=$line;
- continue;
- }
-
-
- if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){
- $fattribute= true;
- $ret .= $line;
- continue;
- }
-
- if ($fattribute){
- if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){
- $fattribute= false;
- $ret .= $line;
- continue;
- }
-
- if (preg_match("/^\*Default$attribute:*\s+/", $line)){
- $line= "*Default$attribute: $value\n";
- $done =true;
- }
- }
- }else{
- if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){
- $fattribute= true;
- $ret .= $line;
- continue;
- }
-
- if ($fattribute){
- if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){
- $fattribute= false;
- $ret .= $line;
- continue;
- }
-
- if (preg_match("/^\*Default$attribute:*\s+/", $line)){
- $line= "*Default$attribute: $value\n";
- $done =true;
- }
- }
- }
- $ret .=$line;
- }
-
- fwrite($wp,$ret);
-
- fclose($wp);
- fclose($rp);
-
- copy("$file.tmp", "$file");
- unlink("$file.tmp");
- }
-
-
- function saveProperties($ppdFile, $properties)
- {
- if(!is_readable($ppdFile)){
- msg_dialog::display(_("PPD manager error"), sprintf(_("Specified PPD file '%s' cannot be opened for reading."),$ppdFile), ERROR_DIALOG);
- }elseif(!is_writeable(preg_replace("#(^.*/).*$#","\\1",$ppdFile.".tmp"))){
- msg_dialog::display(_("PPD manager error"), sprintf(_("The temporary file '%s' cannot be opened for writing."),$ppdFile.".tmp"), ERROR_DIALOG);
- }else{
- foreach ($properties as $name => $section){
- foreach ($section as $attribute => $value){
- if (is_array($value)){
- $this->updateAttribute($ppdFile, $name, $attribute, $value['_default']);
- }
- }
- }
- }
- }
-
- function loadProperties($ppdFile)
- {
- $group= "";
- $option= "";
- $properties= array();
-
- $fh= fopen ($ppdFile, 'r');
- while (!feof($fh)) {
-
- /* Read line */
- $line= fgets($fh, 256);
- if (strlen($line) >= 256){
- trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING);
- }
-
- /* Trigger for option groups */
- if (preg_match('/^\*OpenGroup:/i', $line)){
-
- /* Sanity checks */
- if ($group != ""){
- trigger_error(_('Nested groups are not supported!'), E_USER_WARNING);
- continue;
- }
- if (in_array($group, $properties)){
- trigger_error(_('Group name not unique!'), E_USER_WARNING);
- continue;
- }
-
- // TODO: Symbol values are not supported yet!
- if (preg_match('/\^/', $line)){
- trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING);
- }
- $complete= preg_replace('@^\*OpenGroup:\s+(.*)$@i', '\1', $line);
- $complete= trim($complete, '"');
- if (preg_match('@/@', $complete)){
- $group= trim(preg_replace('@^\*OpenGroup:\s+"?([^/]+)/.*$@i', '\1', $line));
- $name = preg_replace('@^\*OpenGroup:\s+"?[^/]+/([^/]+).*$@i', '\1', $line);
- } else {
- $group= $complete;
- $name = $complete;
- }
- $properties[$group]= array('_name' => $name);
- continue;
- }
- if (preg_match("/^\*CloseGroup:\s+\"?$group\"?/i", $line)){
- $group= "";
- continue;
- }
-
- /* Trigger for options */
- if (preg_match('/^\*OpenUI\s+/i', $line)){
-
- /* Sanity check */
- if ($option != ""){
- trigger_error(_('Nested options are not supported!'), E_USER_WARNING);
- continue;
- }
-
- // TODO: Symbol values are not supported yet!
- if (preg_match('/\^/', $line)){
- trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING);
- }
- $complete= preg_replace('@^\*OpenUI\s+(.*)$@i', '\1', $line);
- $complete= trim($complete, '"');
- if (preg_match('@/@', $complete)){
- $option= trim(preg_replace('@^\*OpenUI\s+([^/]+)/.*$@i', '\1', $line));
- $name = trim(preg_replace('@^\*OpenUI\s+[^/]+/([^/]+).*$@i', '\1', $line));
- } else {
- $option= trim($complete);
- $name = trim($complete);
- }
-
- /* Extract option type */
- $type= trim(preg_replace('/^[^:]+:\s+/', '', $line));
- $name= preg_replace('/:.*$/', '', $name);
- $option= preg_replace('/:.*$/', '', $option);
-
- // TODO: PickMany is not supported yet!
- if (preg_match('/PickMany/i', $type)){
- trigger_error(_('PickMany is not supported yet!'), E_USER_WARNING);
- }
- if(empty($group)){
- $properties["NO_SECTION"][$option]= array('_name' => $name, '_type' => $type);
- }else{
- $properties[$group][$option]= array('_name' => $name, '_type' => $type);
- }
- continue;
- }
- /* Show interest for option parsing */
- if ($option != ""){
-
- $eoption= preg_replace('@\*@', '', $option);
-
- /* Close section? */
- if (preg_match("@^\*CloseUI:\s+\*$eoption@i", $line)){
- $option= "";
- continue;
- }
-
- /* Default value? */
- if (preg_match("@^\*Default$eoption:@", $line)){
- $c= preg_replace("@^\*Default$eoption:\s+@", "", $line);
- if(empty($group)){
- $properties["NO_SECTION"][$option]['_default']= trim(trim($c, '"'));
- }else{
- $properties[$group][$option]['_default']= trim(trim($c, '"'));
- }
- continue;
- }
-
- /* Possible value? */
- if (preg_match("@^\*$eoption\s+@", $line)){
-#*PageSize Letter/US Letter: "<>setpagedevice"
- $c= preg_replace("@^\*$eoption\s+([^/]+).*$@", "$1", $line);
- $d= preg_replace("@^\*$eoption\s+[^/]+/([^:]+).*$@", "$1", $line);
- if(empty($group)){
- $properties["NO_SECTION"][$option][trim($c)]= trim($d);
- }else{
- $properties[$group][$option][trim($c)]= trim($d);
- }
- continue;
- }
- }
- }
- fclose ($fh);
- return ($properties);
- }
-
- function loadDescription($ppdFile)
- {
- $model= "";
- $manufacturer= "";
-
-
- /* Only parse complete PPD file again, if it was changed */
- $modified = filemtime($ppdFile);
- if(isset($this->cachedList[$ppdFile]) && isset($this->timestamps[$ppdFile]) && $modified == $this->timestamps[$ppdFile]){
- return($this->cachedList[$ppdFile]);
- }
-
- /* Remember modified timestamp, to speed up next request */
- $this->timestamps[$ppdFile] = filemtime($ppdFile);
-
- $fh= fopen ($ppdFile, 'r');
- while ((!feof($fh))&&($fh)) {
-
- /* Read line */
- $line= fgets($fh, 256);
- if (strlen($line) >= 256){
- trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING);
- }
-
- /* Extract interesting informations */
- if (preg_match('/^\*Manufacturer:/i', $line)){
- $manufacturer= preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line);
- }
- if (preg_match('/^\*ModelName:/i', $line)){
- $model= preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line);
- }
-
- /* Got everything we need? Skip rest for speed reasons... */
- if ($model != '' && $manufacturer != ''){
- break;
- }
- }
- fclose ($fh);
-
- /* Write out a notice that the PPD file seems to be broken if we can't
- extract any usefull informations */
- if ($model == '' || $manufacturer == ''){
- trigger_error(sprintf(_('Parsing PPD file %s failed - no information found.'), $ppdFile), E_USER_WARNING);
- }
-
- return ($manufacturer.' - '.$model);
- }
-
-
- function getPrinterList($reload= false)
- {
- /* Load list of PPD files */
- if (count($this->cachedList) == 0 || $reload){
- $list= $this->findPPD($this->path);
-
- /* Load descriptive informations to build final printer list */
- $new = array();
- foreach ($list as $ppdFile){
- $new[$ppdFile] = $this->loadDescription($ppdFile);
- }
- $this->cachedList= $new ;
-
- }
-
- return ($this->cachedList);
- }
-
-}
-
-?>
diff --git a/gosa-core/include/class_sambaMungedDial.inc b/gosa-core/include/class_sambaMungedDial.inc
+++ /dev/null
@@ -1,609 +0,0 @@
-<?php
-/*
- This code is part of GOsa (https://gosa.gonicus.de)
- Copyright (C) 2004 Cajus Pollmeier
-
- This program 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.
-
- This program 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 this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-*/
-
-
-/* File header is treated as constant. It cannot be defined inside the class if $PHP_VERSION < 5 */
-define ("FILEHEADER",
- "20002000200020002000200020002000".
- "20002000200020002000200020002000".
- "20002000200020002000200020002000".
- "20002000200020002000200020002000".
- "20002000200020002000200020002000".
- "20002000200020002000200020002000".
- "5000");
-/* This is the old header, it is needed to automatically convert old mungedDials to new ones */
-define ("FILEHEADER_OLD",
- "6d000800200020002000200020002000".
- "20002000200020002000200020002000".
- "20002000200020002000200064000100".
- "20002000200020002000200020002000".
- "20002000200020002000200020002000".
- "20002000200020002000200020002000".
- "50001000");
-
-class sambaMungedDial
-{
- /* Terminal server variables (samba3) */
- var $ctx= array(
- 'CtxCfgPresent' => '551e0bb0',
- 'CtxCfgFlags1' => '00e00010',
- 'CtxCallback' => '',
- 'CtxShadow' => '01000000',
- 'CtxMaxConnectionTime' => '',
- 'CtxMaxDisconnectionTime' => '',
- 'CtxMaxIdleTime' => '',
- 'CtxKeyboardLayout' => '',
- 'CtxMinEncryptionLevel' => '00',
- 'CtxWorkDirectory' => '',
- 'CtxNWLogonServer' => '',
- 'CtxWFHomeDir' => '',
- 'CtxWFHomeDirDrive' => '',
- 'CtxWFProfilePath' => '',
- 'CtxInitialProgram' => '',
- 'CtxCallbackNumber' => '');
-
- /* attribute list for save action */
- var $ctxattributes= array("CtxCfgPresent", "CtxCfgFlags1", "CtxCallback",
- "CtxShadow", "CtxMaxConnectionTime", "CtxMaxDisconnectionTime",
- "CtxMaxIdleTime", "CtxKeyboardLayout", "CtxMinEncryptionLevel",
- "CtxWorkDirectory", "CtxNWLogonServer", "CtxWFHomeDir",
- "CtxWFHomeDirDrive", "CtxWFProfilePath", "CtxInitialProgram",
- "CtxCallbackNumber");
-
- /* These parameters are treated as strings and get a trailing zero */
- var $stringParams= array( "CtxWorkDirectory", "CtxNWLogonServer",
- "CtxWFHomeDir", "CtxWFHomeDirDrive",
- "CtxWFProfilePath", "CtxInitialProgram", "CtxCallbackNumber");
-
- /* These parameters are treated as time values and get converted */
- var $timeParams= array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime");
-
- var $old_behavior= false;
-
- function strhex($string)
- {
- $hex="";
-
- for ($i=0; $i<strlen($string); $i++) {
- $hex.= dechex(ord($string[$i]));
- }
-
- return ($hex);
- }
-
- function hexstr($hex)
- {
- $string="";
-
- for ($i=0; $i<strlen($hex)-1; $i+=2) {
- $string.= chr(hexdec($hex[$i].$hex[$i+1]));
- }
-
- return ($string);
- }
-
- function endian($src)
- {
- return (substr($src, 2, 2).substr($src, 0, 2));
- }
-
- function genTime ($minutes)
- {
- $usec= (int) ($minutes * 60 * 1000);
- $src= sprintf('%04x%04x', $usec & 0x0FFFF, ($usec & 0x0FFFF0000) >> 16);
- return (sambaMungedDial::endian(substr($src, 0, 4)).sambaMungedDial::endian(substr($src, 4, 4)));
- }
-
- function readTime ($time)
- {
- $lo= substr($time, 0, 4);
- $hi= substr($time, 4, 4);
-
- $usecs= (hexdec(substr($lo, 2, 2)) * 256 + hexdec(substr($lo, 0, 2))) +
- (hexdec(substr($hi, 2 ,2)) * 256 + hexdec(substr($hi, 0, 2))) * 256 * 256;
-
- return ((int)($usecs / (60 * 1000)));
- }
-
- function to8bit($string)
- {
- $result= "";
-
- /* Strip zeros */
- for ($i= 0; $i<strlen($string); $i++){
- if ($string[$i] != chr(0)){
- $result.= $string[$i];
- }
- }
-
- return ($result);
- }
-
- function is_samba_path($path)
- {
- if ($path == ""){
- return (TRUE);
- }
-
- if (!preg_match('/^[a-z0-9%\\\\_.:+-\\\\$]+$/i', $path)){
- return (FALSE);
- }
-
- return preg_match ("/\\\\.+$/", $path);
- }
-
- /* Encode full MungedDial-String */
- function encode_munged ($params)
- {
- /* Walk through the parameters and convert them */
- $result= sambaMungedDial::hexstr(FILEHEADER);
-
- // CHANGED: We need to insert the number of attributes right after FILEHEADER.
- $counter= 0;
- $result_tmp= "";
- foreach ($params as $paramName => $paramValue) {
- /* String parameter? */
- if (in_array($paramName, $this->stringParams)){
- $isString= TRUE;
- $paramValue= sambaMungedDial::strhex($paramValue.chr(0).chr(0));
- } else {
- $isString= FALSE;
- }
-
- /* Time parameter? */
- if (in_array($paramName, $this->timeParams)){
- $paramValue= sambaMungedDial::genTime($paramValue);
- }
-
- $result_tmp.= sambaMungedDial::munge($paramName, $paramValue, $isString);
- $counter++;
- }
-
- // First add the number of attributes
- $result.= sambaMungedDial::hexstr(sprintf("%02x00", $counter));
-
- // Then the usual stuff
- $result.= $result_tmp;
-
- return ($result);
- }
-
- /* Setup parameter given by paramName to MungedDial-Format */
- function munge($paramName, $paramValue, $isString)
- {
- $result= "";
-
- /* Encode paramName to UTF-16 */
- if (function_exists("recode")){
- $utfName= recode("ISO8859-15..UTF-16", $paramName);
- } else {
- $utfName= iconv("ISO8859-15", "UTF-16BE", $paramName);
- }
-
- /* Set parameter length, high and low byte */
- $paramLen= strlen($utfName);
- $result.= chr($paramLen & 0x0FF);
- $result.= chr(($paramLen & 0x0FF00) >> 8);
-
- /* String parameters have additional trailing bytes */
- $valueLen= strlen($paramValue);
- $result.= chr($valueLen & 0x0FF);
- $result.= chr(($valueLen & 0x0FF00) >> 8);
-
- /* Length fields have a trailing '01' appended by the UTF-16 converted name */
- $result.= chr(1);
- $result.= $utfName;
-
- /* Parameter is padded with '00' */
- $result.= chr(0);
- $result.= $paramValue;
-
- /* Append a trailing '00' to string parameters */
- if ($isString && (strlen($paramValue) & 1)){
- $result.= chr(0);
- }
-
- return ($result);
- }
-
- /* Takes a base64-encoded MungedDial-String and returns an array of included parameters and values */
- function decode_munged($munge)
- {
- $result= array();
-
- /*
- * Remove base64 encoding and skip FILEHEADER.
- * The '4' is added, because the FILEHEADER has been stripped by 4 chars.
- * This is the number of attributes following - we don't need this at read time, only when writing.
- */
- if(substr(base64_decode($munge),0,2)=="6d") {
- $this->old_behavior=true;
- }
-
- $ctxField="";
- if($this->old_behavior==true) {
- $ctxField= substr(base64_decode($munge), (strlen(FILEHEADER_OLD)) / 2);
- } else {
- $ctxField= substr(base64_decode($munge), (strlen(FILEHEADER)+4) / 2);
- }
-
- /* Decode parameters */
- while ($ctxField!=""){
-
- /* Read value lengths */
- $ctxParmNameLength= ord($ctxField[0]) + 16 * ord($ctxField[1]);
- $ctxParmLength= ord($ctxField[2]) + 16 * ord($ctxField[3]);
-
- /* Reposition ctxField on start of parameter name, read parameter name */
- $ctxField= substr($ctxField, 6);
- $ctxParmName= sambaMungedDial::to8bit(substr($ctxField, 0, $ctxParmNameLength));
-
- /* Reposition ctxField on start of parameter */
- $ctxField= substr($ctxField, $ctxParmNameLength);
- $ctxParm= substr($ctxField, 0, $ctxParmLength);
-
- /* If string parameter, convert */
- if (in_array($ctxParmName, $this->stringParams)){
- $ctxParm= sambaMungedDial::hexstr($ctxParm);
- }
- /* If time parameter, convert */
- if (in_array($ctxParmName, $this->timeParams)){
- $ctxParm= sambaMungedDial::readTime($ctxParm);
- }
-
- /* Assign in result array */
- $result[$ctxParmName]= trim($ctxParm);
-
- /* Reposition ctxField on end of parameter and continue */
- $ctxField= substr($ctxField, $ctxParmLength);
- }
-
- return ($result);
- }
-
- /* function takes a base64-encoded sambaMungedDial */
- function load ($mungedDial)
- {
- $this->ctx= $this->decode_munged($mungedDial);
- }
-
- /* Returns ready-to-run mungedDialString to be filled into ldap */
- function getMunged ()
- {
- // Do extra check for valid timeParams (they must be set to 0 if disabled)
- foreach($this->timeParams as $value) {
- if(!isset($this->ctx[$value])) {
- $this->ctx[$value]= 0;
- }
- }
- $result= base64_encode($this->encode_munged($this->ctx));
-
- return $result;
- }
-
- /* Returns array of flags, which can be set on-demand with activated java-script */
- function getOnDemandFlags ()
- {
- $result= array();
- if (session::get("js")){
- foreach ($this->timeParams as $value) {
- if (!isset($this->ctx[$value]) || (isset($this->ctx[$value]) && $this->ctx[$value] == 0)) {
- $result[$value."Mode"]= "disabled";
- } else {
- $result[$value."Mode"]= "";
- }
- }
-
- if (substr($this->ctx['CtxCfgFlags1'], 6, 1) == "1") {
- $result['CtxInitialProgramMode'] = "disabled";
- } else {
- $result['CtxInitialProgramMode'] = "";
- }
- }else{
- foreach ($this->timeParams as $value) {
- $result[$value."Mode"]= "";
- }
-
- $result['CtxInitialProgramMode'] = "";
-
- }
-
- return $result;
- }
-
- /*Gets Terminal-Server-Login value: enabled/disabled */
- function getTsLogin ()
- {
- $flags= ord(substr($this->ctx['CtxCfgFlags1'], 5, 1));
-
- if ($flags & 1) {
- $result= false;
- } else {
- $result= true;
- }
-
- return $result;
- }
-
- /* Sets Terminal-Server-Login value: enabled/disabled */
- function setTsLogin ($checked)
- {
- $flag= substr($this->ctx['CtxCfgFlags1'], 5, 1);
-
- if ($checked) {
- $flag|= 1;
- } else {
- $flag&= 0xFE;
- }
-
- $this->ctx['CtxCfgFlags1'][5]= sprintf('%1x', $flag);
- }
-
- /* gets Broken-Connection value: disconnect/reset */
- function getBrokenConn ()
- {
- $flags= ord(substr($this->ctx['CtxCfgFlags1'], 5, 1));
- if ($flags & 4) {
- $result= "1";
- } else {
- $result= "0";
- }
-
- return $result;
- }
-
- /* sets Broken-Connection value: disconnect/reset */
- function setBrokenConn ($checked)
- {
- $flag= substr($this->ctx['CtxCfgFlags1'], 5, 1);
-
- if ($checked) {
- $flag|= 4;
- } else {
- $flag&= 0xFB;
- }
-
- $this->ctx['CtxCfgFlags1'][5]= sprintf('%1x', $flag);
- }
-
- /* gets Reconnection value: from any client/from previous client only */
- function getReConn ()
- {
- $flags= ord(substr($this->ctx['CtxCfgFlags1'], 5, 1));
- if ($flags & 2) {
- $result= "1";
- } else {
- $result= "0";
- }
-
- return $result;
- }
-
- /* sets Reconnection value: from any client/from previous client only */
- function setReConn ($checked)
- {
- $flag= substr($this->ctx['CtxCfgFlags1'], 5, 1);
-
- if ($checked) {
- $flag|= 2;
- } else {
- $flag&= 0xFD;
- }
-
- $this->ctx['CtxCfgFlags1'][5]= sprintf('%1x', $flag);
- }
-
- /* gets Inherit-config-from-client value: enabled/disabled */
- function getInheritMode ()
- {
- if (substr($this->ctx['CtxCfgFlags1'], 6, 1) == "1") {
- $result= true;
- } else {
- $result= false;
- }
-
- return $result;
- }
-
- /* sets Inherit-config-from-client value: enabled/disabled */
- function setInheritMode ($checked)
- {
- if ($checked) {
- $this->ctx['CtxCfgFlags1'][6]= "1";
- } else {
- $this->ctx['CtxCfgFlags1'][6]= "0";
- }
- }
-
- /* gets shadow value (enum): 0-4
- 0: disabled
- 1: input on, notify on
- 2: input on, notify off
- 3: input off, notify on
- 4: input off, notify off
- */
- function getShadow ()
- {
- if($this->old_behavior==true) {
- $result= substr($this->ctx['CtxCfgFlags1'], 1, 1);
- } else {
- $result= substr($this->ctx['CtxShadow'], 1, 1);
- }
- return $result;
- }
-
- /* sets shadow value */
- function setShadow ($checked, $value)
- {
- if ($checked) {
- if($this->old_behavior==true) {
- // We need to reset the old setting
- $this->ctx['CtxCfgFlags1'][1]= sprintf('%1X', $value);
- }
- $this->ctx['CtxShadow'][1]= sprintf('%1x', $value);
- }
- }
-
- /* gets connect-client-drive-at-logon value: enabled/disabled */
- function getConnectClientDrives ()
- {
- $connections= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
- if ($connections & 8) {
- $result= true;
- } else {
- $result= false;
- }
-
- return $result;
- }
-
- /* sets connect-client-drive-at-logon value: enabled/disabled */
- function setConnectClientDrives ($checked)
- {
- $flag= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
- if ($checked) {
- $flag|= 8;
- } else {
- $flag&= 0xF7;
- }
-
- $this->ctx['CtxCfgFlags1'][2]= sprintf('%1x', $flag);
- }
-
- /* gets connect-client-printers-at-logon value: enabled/disabled */
- function getConnectClientPrinters ()
- {
- $connections= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
- if ($connections & 4) {
- $result= true;
- } else {
- $result= false;
- }
-
- return $result;
- }
-
- /* sets connect-client-printers-at-logon value: enabled/disabled */
- function setConnectClientPrinters ($checked)
- {
- $flag= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
-
- if ($checked) {
- $flag|= 4;
- } else {
- $flag&= 0xFB;
- }
-
- $this->ctx['CtxCfgFlags1'][2]= sprintf('%1x', $flag);
- }
-
- /* gets set-client-printer-to-default value: enabled/disabled */
- function getDefaultPrinter ()
- {
- $connections= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
- if ($connections & 2) {
- $result= true;
- } else {
- $result= false;
- }
-
- return $result;
- }
-
- /* sets set-client-printer-to-default value: enabled/disabled */
- function setDefaultPrinter ($checked)
- {
- $flag= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
-
- if ($checked) {
- $flag|= 2;
- } else {
- $flag&= 0xFD;
- }
-
- $this->ctx['CtxCfgFlags1'][2]= sprintf('%1x', $flag);
- }
-
- /* SMARTY: gets the checkbox state of "Connection" */
- function getCtxMaxConnectionTimeF ()
- {
- // Connection Time is 0 if disabled
- if (isset($this->ctx['CtxMaxConnectionTime']) && ($this->ctx['CtxMaxConnectionTime'] != 0)) {
- $result= true;
- } else {
- $result= false;
- }
-
- return $result;
- }
-
- /* SMARTY: sets the checkbox "Connection" to unchecked */
- function setCtxMaxConnectionTimeF ($checked)
- {
- if ($checked) {
- unset ($this->ctx['CtxMaxConnectionTime']);
- }
- }
-
- /* SMARTY: gets the checkbox state of "Disconnection" */
- function getCtxMaxDisconnectionTimeF ()
- {
- // Connection Time is 0 if disabled
- if (isset($this->ctx['CtxMaxDisconnectionTime']) && ($this->ctx['CtxMaxDisconnectionTime'] != 0)) {
- $result= true;
- } else {
- $result= false;
- }
-
- return $result;
- }
-
- /* SMARTY: sets the checkbox "Disconnection" to unchecked */
- function setCtxMaxDisconnectionTimeF ($checked)
- {
- if ($checked) {
- unset ($this->ctx['CtxMaxDisconnectionTime']);
- }
- }
-
- /* SMARTY: gets the checkbox state of "Idle" */
- function getCtxMaxIdleTimeF ()
- {
- // Connection Time is 0 if disabled
- if (isset($this->ctx['CtxMaxIdleTime']) && ($this->ctx['CtxMaxIdleTime'] != 0)) {
- $result= true;
- } else {
- $result= false;
- }
-
- return $result;
- }
-
- /* SMARTY: sets the checkbox "Idle" to unchecked */
- function setCtxMaxIdleTimeF ($checked)
- {
- if ($checked) {
- unset ($this->ctx['CtxMaxIdleTime']);
- }
- }
-}
-
-// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
-?>
diff --git a/gosa-core/include/password-methods/class_password-methods.inc b/gosa-core/include/password-methods/class_password-methods.inc
--- /dev/null
@@ -0,0 +1,131 @@
+<?php
+/*
+ This code is part of GOsa (https://gosa.gonicus.de)
+ Copyright (C) 2004 Cajus Pollmeier
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+class passwordMethod
+{
+ var $config = false;
+ var $attrs= array();
+
+ // Konstructor
+ function passwordMethod($config)
+ {
+ }
+
+
+ function get_hash_name()
+ {
+ }
+
+ // Loads Methods in annother way as get_available_methods do, (For setup ..)
+ // and loads them,.
+ function get_available_methods_if_not_loaded($path_to_load="../include")
+ {
+ $oh = opendir($path_to_load);
+ $i = 0;
+ $ret = false;
+ while ($file = readdir($oh)) {
+ $one = strtolower($file);
+ if((strstr($one,"class_password-methods-" ))&&($one[0]!=".")){
+ require_once($file);
+ }
+ }
+ return(passwordMethod::get_available_methods());
+ }
+
+
+
+ // Crypts a single string, with given Method
+ function crypt_single_str($string,$method)
+ {
+ $available = passwordMethod::get_available_methods();
+ if(!is_array($available))
+ {
+ $available = passwordMethod::get_available_methods_if_not_loaded();
+ }
+
+ $test = new $available[$method](false);
+ $newpass = $test->generate_hash($string);
+ return( $newpass);
+ }
+
+
+ // this function returns all loaded classes for password encryption
+ static function get_available_methods()
+ {
+ global $class_mapping, $config;
+ $ret =false;
+ $i =0;
+ foreach($class_mapping as $class => $path) {
+ if(preg_match('/passwordMethod/i', $class) && !preg_match("/^passwordMethod$/i", $class)){
+ $name = preg_replace ("/passwordMethod/i", "", $class);
+ $test = new $class($config);
+ if($test->is_available()) {
+ $plugname= $test->get_hash_name();
+ $ret['name'][$i]= $plugname;
+ $ret['class'][$i]=$class;
+ $ret[$i]['name']= $plugname;
+ $ret[$i]['class']= $class;
+ $ret[$plugname]=$class;
+ $i++;
+ }
+ }
+ }
+ return($ret);
+ }
+
+
+ // Method to let password backends remove additional information besides
+ // the userPassword attribute
+ function remove_from_parent()
+ {
+ }
+
+
+ // Method to let passwords backends manage additional information
+ // besides the userAttribute entry
+ function set_password($password)
+ {
+ }
+
+
+ // Return true if this password method provides a configuration dialog
+ function is_configurable()
+ {
+ return FALSE;
+ }
+
+
+ // Provide a subdialog to configure a password method
+ function configure()
+ {
+ return "";
+ }
+
+
+ // Save information to LDAP
+ function save($dn)
+ {
+ }
+
+
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-core/plugins/admin/fai/class_debconfTemplate.inc b/gosa-core/plugins/admin/fai/class_debconfTemplate.inc
--- /dev/null
@@ -0,0 +1,428 @@
+<?php
+
+class debconf
+{
+ var $package= "";
+ var $language= "";
+ var $loaded_template= FALSE;
+ var $template_directory= "";
+ var $template= array();
+
+
+ function debconf($package= "", $language= "")
+ {
+ $this->set_language($language);
+ $this->set_package($package);
+ }
+
+
+ function set_package($package)
+ {
+ $this->package= $package;
+ }
+
+
+ function set_template_directory($directory)
+ {
+ if (is_dir($directory) && is_readable($directory)){
+ $this->template_directory = $directory;
+ return TRUE;
+ }
+
+ $this->template_directory= "";
+ return FALSE;
+ }
+
+
+ function set_language($language)
+ {
+ $this->language= $language;
+ }
+
+
+ function load()
+ {
+ if( TRUE === $this->has_template() ) {
+
+ /* Try to load package based template file */
+ $this->template= array();
+
+ /* Read template array */
+ $post_name = 0;
+ $langcode = $this->language.".UTF-8";
+ $in_description = FALSE;
+ $got_local_description = FALSE;
+
+ /* get filename */
+ $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates");
+
+ /* Check if file is readable */
+ if (!is_file($filename) || !is_readable($filename)){
+ return(FALSE);
+ }
+
+ /* Open file and read content line by line */
+ $fh= fopen($filename, 'r');
+
+ /* While the file handle is valid && there is still data to read -> parse configuration file */
+ while ($fh && !feof($fh)){
+ $line= fgets($fh, 1024);
+
+ /* Reset description flag */
+ if ($in_description && !preg_match("/^ /", $line)){
+ $in_description= FALSE;
+ }
+
+ /* Template header */
+ if (preg_match("/^Template: /", $line)){
+ $post_name ++;
+ $name= trim(preg_replace("/^Template: (.*)$/", "\\1", $line));
+ $this->template[$post_name]['Name'] = $name;
+ $this->template[$post_name]['Default'] ="";
+
+ $got_local_description= FALSE;
+ continue;
+ }
+
+ /* Get type */
+ if (preg_match("/^Type: /", $line)){
+ $type= trim(preg_replace("/^Type: (.*)$/", "\\1", $line));
+ $this->template[$post_name]['Type']= $type;
+ continue;
+ }
+
+ /* Get default */
+ if (preg_match("/^Default: /", $line)){
+ $this->template[$post_name]['Default']= "";
+ $default= trim(preg_replace("/^Default: (.*)$/", "\\1", $line));
+ $this->template[$post_name]['Default']= $default;
+ continue;
+ }
+
+ /* Get description */
+ if (!$got_local_description && preg_match("/^Description: /", $line)){
+ $this->template[$post_name]['Description']= "";
+ $description= trim(preg_replace("/^Description: (.*)$/", "\\1", $line));
+ $this->template[$post_name]['Topic']= $description;
+ $this->template[$post_name]['Description']= "";
+ $in_description= TRUE;
+ continue;
+ }
+
+ /* Fill description */
+ if (!$got_local_description && $in_description){
+ $description= preg_replace("/^ (.*)$/", "\\1", $line);
+ $this->template[$post_name]['Description'].= $description;
+ continue;
+ }
+
+ /* Get local description */
+ if (preg_match("/^Description-$langcode: /", $line)){
+ $description= trim(preg_replace("/^Description-$langcode: (.*)$/", "\\1", $line));
+ $this->template[$post_name]['Topic']= $description;
+ $in_description= TRUE;
+ $got_local_description= TRUE;
+ $this->template[$post_name]['Description']= "";
+ continue;
+ }
+
+ /* Fill local description */
+ if ($got_local_description && $in_description){
+ $description= preg_replace("/^ (.*)$/", "\\1", $line);
+ $this->template[$post_name]['Description'].= $description;
+ continue;
+ }
+
+ /* Get native choices */
+ if (preg_match("/^Choices: /", $line)){
+ $type= trim(preg_replace("/^Choices: (.*)$/", "\\1", $line));
+ $this->template[$post_name]['Choices']= $type;
+ }
+
+ /* Get local choices */
+ if (preg_match("/^Choices-$langcode: /", $line)){
+ $type= trim(preg_replace("/^Choices-$langcode: (.*)$/", "\\1", $line));
+ $this->template[$post_name]['Choices-local']= $type;
+ }
+
+ }
+
+ fclose($fh);
+ $this->loaded_template= TRUE;
+
+ $tmp= array();
+ foreach($this->template as $post_name => $template){
+ $template['post_name'] = "post_".$post_name;
+ $tmp[] = $template;
+ }
+ $this->template = $tmp;
+
+ return (TRUE);
+ }
+
+ $this->loaded_template= FALSE;
+ return (FALSE);
+ }
+
+
+ function has_template()
+ {
+ /* Reject requests, if parameters are not set */
+ if ($this->package == "" || $this->template_directory == ""){
+ return (FALSE);
+ }
+ $filename= preg_replace("/\/+/", "/", $this->template_directory."/".$this->package.".templates");
+ return (is_file($filename) && is_readable($filename));
+ }
+
+
+ /* Check if some fields are posted */
+ function PostCheck()
+ {
+ /* Walk through all template variables */
+ foreach($this->template as $post_name => $entry){
+
+ /* Check if this var is set*/
+ if(isset($_POST[$entry['post_name']])){
+
+ /* special handling for arrays */
+ if(is_array($_POST[$entry['post_name']])){
+ $str = "";
+ foreach($_POST[$entry['post_name']] as $val){
+ $str.= $val.", ";
+ }
+ $str = preg_replace("/\,\ $/","",$str);
+ $this->template[$post_name]['Default'] = $str;
+ }else{
+ $this->template[$post_name]['Default'] = $_POST[$entry['post_name']];
+ }
+ }
+ }
+
+ foreach($this->template as $post_name => $entry){
+ if(isset($_POST["multi-".$entry['post_name']])){
+ $this->template[$post_name]['Default']= "";
+ foreach($_POST as $name => $value){
+ if(preg_match("/".$entry['post_name']."-multi-/",$name)){
+ $this->template[$post_name]['Default'] .= $value.", ";
+ }
+ }
+ $this->template[$post_name]['Default'] = preg_replace("/, $/","",$this->template[$post_name]['Default']);
+ }
+ }
+
+
+ }
+
+
+ /* This funtion sets the defualt value */
+ function SetDefault($var,$val)
+ {
+ if ($this->loaded_template) {
+ foreach($this->template as $key => $tmp){
+ if($tmp['Name'] == $var ){
+ $this->template[$key]['Default'] = $val;
+ }
+ }
+ }
+ }
+
+
+ /* Display all possible options in html*/
+ function get_dialog()
+ {
+ if ($this->loaded_template) {
+ $result= "<table summary=''>";
+
+ foreach ($this->template as $post_name => $entry){
+
+ $types= array("boolean" => "", "multiselect" => "", "note" => "",
+ "password" => "", "select" => "", "string" => "", "text" => "", "title" => "");
+
+ /* Check if type is available */
+ if ((isset($entry['Type']))&&(isset($types[$entry['Type']]))){
+
+ /* Produce type specific output */
+ $fn= "render_".$entry['Type'];
+ $str = $this->$fn($entry);
+ if(!empty($str)){
+ $result.=$str."<tr><td colspan='2'><p class='seperator'> </p></td></tr>";
+ }
+ } else {
+ //php_error(E_WARNING, "An unknown type has been specified in the debconf template. Please fix.");
+ }
+ }
+
+
+ $result .= "<input type='hidden' post_name='check_post' value='1'></table>";
+ return ($result);
+ } else {
+ return _("This package has no debconf options.");
+ }
+ }
+
+
+ function render_boolean($data)
+ {
+
+ $post_name= $data['post_name'];
+ $result="
+ <tr>
+ <td valign='top' style='width:100%'>
+ <h2>".$data['Topic']."</h2>".$data['Description']."
+ </td>
+ <td style=\"white-space:nowrap; vertical-align:top; border-left: 1px solid rgb(160, 160, 160);\">";
+
+ foreach(array("true","false") as $value){
+ if($data['Default'] == $value){
+ $result.="<input type='radio' name='".$data['post_name']."' value='".$value."' checked>"._($value);
+ }else{
+ $result.="<input type='radio' name='".$data['post_name']."' value='".$value."' >"._($value);
+ }
+ $result.="<br>";
+ }
+
+ $result.= "
+ </td>
+ </tr>
+ ";
+
+ return ($result);
+ }
+
+
+ function render_multiselect($data)
+ {
+ $post_name= $data['post_name'];
+ if (preg_match('/\$\{/', $data['Choices'])){
+ $result= $this->render_string($data);
+ } else {
+ $choices= "";
+ foreach (split(", ", $data['Choices']) as $choice){
+ $choices[]= $choice;
+ }
+
+
+ $result="
+ <tr>
+ <td valign='top'>
+ <h2>".$data['Topic']."</h2>".$data['Description']."
+ </td>
+ <td valign='top' style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\">
+ <input type='hidden' name='multi-".$post_name."' value='1'>
+ ";
+
+ $defs = split(", ",$data['Default']);
+ foreach($choices as $value){
+ if(in_array($value,$defs)){
+ $result.="\n<input name='".$post_name."-multi-".$value."' type='checkbox' value='".htmlentities($value)."' checked>".$value."<br>";
+ }else{
+ $result.="\n<input name='".$post_name."-multi-".$value."' type='checkbox' value='".htmlentities($value)."'>".$value."<br>";
+ }
+ }
+
+ $result .= "</td>
+ </tr>
+ ";
+ }
+
+ return ($result);
+ }
+
+
+ function render_note($data)
+ {
+ /* Ignore notes, they do not makes sense, since we don't get any
+ chance to test entered values... */
+ return ("");
+ }
+
+
+ function render_password($data)
+ {
+ $result= "";
+ $result.= "<tr><td valign='top'>";
+ $result.= "<h2>".$data['Topic']."</h2>".$data['Description']."</td><td style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\"> <input type='text' name='".$data['post_name']."' value='".$data['Default']."'></b><br><br>";
+ $result.= $data['Description'];
+ $result.= "</td>";
+
+ return ($result);
+ }
+
+
+ function render_select($data)
+ {
+ $post_name= $data['post_name'];
+
+ if (preg_match('/\$\{/', $data['Choices'])){
+ $choices= array("Need to use some text...");
+ } else {
+ $choices= "";
+ foreach (split(", ", $data['Choices']) as $choice){
+ $choices[]= $choice;
+ }
+ }
+
+
+ $result="
+
+ <tr>
+ <td valign='top'>
+ <h2>".$data['Topic']."</h2>".$data['Description']."
+ </td>
+ <td valign='top' style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\">
+ ";
+
+ foreach($choices as $value){
+ if($data['Default'] == $value){
+ $result.="\n<input type='radio' name='".$post_name."' value='".htmlentities($value)."' checked >".htmlentities($value)."<br>";
+ }else{
+ $result.="\n<input type='radio' name='".$post_name."' value='".htmlentities($value)."'>".htmlentities($value)."<br>";
+ }
+ }
+
+ $result.= "
+
+ </td>
+ </tr>
+ ";
+
+ return ($result);
+ }
+
+
+ function render_string($data)
+ {
+ $result= "
+ <tr>
+ <td valign='top'>
+ <h2>".$data['Topic']."</h2>".$data['Description']."
+ </td>
+ <td style=\"white-space:nowrap; border-left: 1px solid rgb(160, 160, 160);\" valign='top'>
+ <input type='text' name='".$data['post_name']."' value='".$data['Default']."' style='width:300px;'>
+ </td>
+ </tr>
+ ";
+
+ return ($result);
+ }
+
+
+ function render_text($data)
+ {
+ /* Ignore text messages, they are normally used for status hints. */
+ return ("");
+ }
+
+
+ function render_title($data)
+ {
+ /* Ignore text messages, they are normally used for status hints. */
+ return ("");
+ }
+
+}
+
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-core/plugins/admin/fai/class_faiManagement.inc b/gosa-core/plugins/admin/fai/class_faiManagement.inc
index 16ae87f73f1bf39cb4424b83803e5c2ac06afb1f..218aae7361b7d277b7eea18c4d02748ff35dc5fa 100644 (file)
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+require_once (BASE_DIR."/include/functions_FAI.inc");
class faiManagement extends plugin
{
diff --git a/gosa-core/plugins/admin/systems/ppd/class_ppdManager.inc b/gosa-core/plugins/admin/systems/ppd/class_ppdManager.inc
--- /dev/null
@@ -0,0 +1,356 @@
+<?php
+
+class ppdManager
+{
+ var $path= "";
+ var $cachedList= array();
+ var $timestamps = array();
+
+ function ppdManager($path)
+ {
+ if(is_dir($path)){
+ $this->path= $path;
+ }else{
+ msg_dialog::display(_("PPD manager error"), sprintf(_("The specified path '%s' does not exist."),$path), ERROR_DIALOG);
+ return (false);
+ }
+ }
+
+
+ function findPPD($path)
+ {
+ $list= array();
+ $currentDir= getcwd();
+
+ $dh = opendir($path);
+ while(false !== ($file = readdir($dh))){
+
+ /* Skip well known files */
+ if( $file == '.' || $file == '..'){
+ continue;
+ }
+
+ /* Recurse through all "common" directories */
+ if(is_dir($path.'/'.$file)){
+ $list= array_merge($list, $this->findPPD($path.'/'.$file));
+ continue;
+ }
+
+ /* Check for PPD extension */
+ if (preg_match('/\.ppd$/i', $file)){
+ $list[]= $path.'/'.$file;
+ }
+ }
+
+ closedir($dh);
+ chdir ($currentDir);
+ return ($list);
+ }
+
+
+ function updateAttribute($file, $section, $attribute, $value)
+ {
+ $fsection= false;
+ $fattribute= false;
+ $section= preg_replace('/^\*/', '', $section);
+ $attribute= preg_replace('/^\*/', '', $attribute);
+
+ $rp= @fopen($file, "r");
+ $wp= @fopen("$file.tmp", "w");
+
+
+
+ while (!feof($rp)){
+ $lines[]= fgets($rp, 1024);
+ }
+
+ $ret = "";
+ $done =false;
+ foreach($lines as $nr => $line){
+
+ if (preg_match("/\*OpenGroup:*\s+\**$section\/*/", $line)){
+ $fsection= true;
+ $ret .=$line;
+ continue;
+ }
+
+ /* Change model name .. */
+ if ((preg_match("/^\*".$attribute.":*\s+/",$line)) && ($attribute == "ModelName")){
+ $line= "*$attribute: \"$value\"\n";
+ $done =true;
+ }
+
+ if (($fsection) && ($section != "NO_SECTION")){
+ if (preg_match("/^\*CloseGroup:*\s+\**$section\/*/", $line)){
+ $fsection= false;
+ $ret .=$line;
+ continue;
+ }
+
+
+ if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){
+ $fattribute= true;
+ $ret .= $line;
+ continue;
+ }
+
+ if ($fattribute){
+ if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){
+ $fattribute= false;
+ $ret .= $line;
+ continue;
+ }
+
+ if (preg_match("/^\*Default$attribute:*\s+/", $line)){
+ $line= "*Default$attribute: $value\n";
+ $done =true;
+ }
+ }
+ }else{
+ if (preg_match("/^\*OpenUI:*\s+\**$attribute\/*/", $line)){
+ $fattribute= true;
+ $ret .= $line;
+ continue;
+ }
+
+ if ($fattribute){
+ if (preg_match("/^\*CloseUI:*\s+\**$attribute\/*/", $line)){
+ $fattribute= false;
+ $ret .= $line;
+ continue;
+ }
+
+ if (preg_match("/^\*Default$attribute:*\s+/", $line)){
+ $line= "*Default$attribute: $value\n";
+ $done =true;
+ }
+ }
+ }
+ $ret .=$line;
+ }
+
+ fwrite($wp,$ret);
+
+ fclose($wp);
+ fclose($rp);
+
+ copy("$file.tmp", "$file");
+ unlink("$file.tmp");
+ }
+
+
+ function saveProperties($ppdFile, $properties)
+ {
+ if(!is_readable($ppdFile)){
+ msg_dialog::display(_("PPD manager error"), sprintf(_("Specified PPD file '%s' cannot be opened for reading."),$ppdFile), ERROR_DIALOG);
+ }elseif(!is_writeable(preg_replace("#(^.*/).*$#","\\1",$ppdFile.".tmp"))){
+ msg_dialog::display(_("PPD manager error"), sprintf(_("The temporary file '%s' cannot be opened for writing."),$ppdFile.".tmp"), ERROR_DIALOG);
+ }else{
+ foreach ($properties as $name => $section){
+ foreach ($section as $attribute => $value){
+ if (is_array($value)){
+ $this->updateAttribute($ppdFile, $name, $attribute, $value['_default']);
+ }
+ }
+ }
+ }
+ }
+
+ function loadProperties($ppdFile)
+ {
+ $group= "";
+ $option= "";
+ $properties= array();
+
+ $fh= fopen ($ppdFile, 'r');
+ while (!feof($fh)) {
+
+ /* Read line */
+ $line= fgets($fh, 256);
+ if (strlen($line) >= 256){
+ trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING);
+ }
+
+ /* Trigger for option groups */
+ if (preg_match('/^\*OpenGroup:/i', $line)){
+
+ /* Sanity checks */
+ if ($group != ""){
+ trigger_error(_('Nested groups are not supported!'), E_USER_WARNING);
+ continue;
+ }
+ if (in_array($group, $properties)){
+ trigger_error(_('Group name not unique!'), E_USER_WARNING);
+ continue;
+ }
+
+ // TODO: Symbol values are not supported yet!
+ if (preg_match('/\^/', $line)){
+ trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING);
+ }
+ $complete= preg_replace('@^\*OpenGroup:\s+(.*)$@i', '\1', $line);
+ $complete= trim($complete, '"');
+ if (preg_match('@/@', $complete)){
+ $group= trim(preg_replace('@^\*OpenGroup:\s+"?([^/]+)/.*$@i', '\1', $line));
+ $name = preg_replace('@^\*OpenGroup:\s+"?[^/]+/([^/]+).*$@i', '\1', $line);
+ } else {
+ $group= $complete;
+ $name = $complete;
+ }
+ $properties[$group]= array('_name' => $name);
+ continue;
+ }
+ if (preg_match("/^\*CloseGroup:\s+\"?$group\"?/i", $line)){
+ $group= "";
+ continue;
+ }
+
+ /* Trigger for options */
+ if (preg_match('/^\*OpenUI\s+/i', $line)){
+
+ /* Sanity check */
+ if ($option != ""){
+ trigger_error(_('Nested options are not supported!'), E_USER_WARNING);
+ continue;
+ }
+
+ // TODO: Symbol values are not supported yet!
+ if (preg_match('/\^/', $line)){
+ trigger_error(_('Symbol values are not supported yet!'), E_USER_WARNING);
+ }
+ $complete= preg_replace('@^\*OpenUI\s+(.*)$@i', '\1', $line);
+ $complete= trim($complete, '"');
+ if (preg_match('@/@', $complete)){
+ $option= trim(preg_replace('@^\*OpenUI\s+([^/]+)/.*$@i', '\1', $line));
+ $name = trim(preg_replace('@^\*OpenUI\s+[^/]+/([^/]+).*$@i', '\1', $line));
+ } else {
+ $option= trim($complete);
+ $name = trim($complete);
+ }
+
+ /* Extract option type */
+ $type= trim(preg_replace('/^[^:]+:\s+/', '', $line));
+ $name= preg_replace('/:.*$/', '', $name);
+ $option= preg_replace('/:.*$/', '', $option);
+
+ // TODO: PickMany is not supported yet!
+ if (preg_match('/PickMany/i', $type)){
+ trigger_error(_('PickMany is not supported yet!'), E_USER_WARNING);
+ }
+ if(empty($group)){
+ $properties["NO_SECTION"][$option]= array('_name' => $name, '_type' => $type);
+ }else{
+ $properties[$group][$option]= array('_name' => $name, '_type' => $type);
+ }
+ continue;
+ }
+ /* Show interest for option parsing */
+ if ($option != ""){
+
+ $eoption= preg_replace('@\*@', '', $option);
+
+ /* Close section? */
+ if (preg_match("@^\*CloseUI:\s+\*$eoption@i", $line)){
+ $option= "";
+ continue;
+ }
+
+ /* Default value? */
+ if (preg_match("@^\*Default$eoption:@", $line)){
+ $c= preg_replace("@^\*Default$eoption:\s+@", "", $line);
+ if(empty($group)){
+ $properties["NO_SECTION"][$option]['_default']= trim(trim($c, '"'));
+ }else{
+ $properties[$group][$option]['_default']= trim(trim($c, '"'));
+ }
+ continue;
+ }
+
+ /* Possible value? */
+ if (preg_match("@^\*$eoption\s+@", $line)){
+#*PageSize Letter/US Letter: "<>setpagedevice"
+ $c= preg_replace("@^\*$eoption\s+([^/]+).*$@", "$1", $line);
+ $d= preg_replace("@^\*$eoption\s+[^/]+/([^:]+).*$@", "$1", $line);
+ if(empty($group)){
+ $properties["NO_SECTION"][$option][trim($c)]= trim($d);
+ }else{
+ $properties[$group][$option][trim($c)]= trim($d);
+ }
+ continue;
+ }
+ }
+ }
+ fclose ($fh);
+ return ($properties);
+ }
+
+ function loadDescription($ppdFile)
+ {
+ $model= "";
+ $manufacturer= "";
+
+
+ /* Only parse complete PPD file again, if it was changed */
+ $modified = filemtime($ppdFile);
+ if(isset($this->cachedList[$ppdFile]) && isset($this->timestamps[$ppdFile]) && $modified == $this->timestamps[$ppdFile]){
+ return($this->cachedList[$ppdFile]);
+ }
+
+ /* Remember modified timestamp, to speed up next request */
+ $this->timestamps[$ppdFile] = filemtime($ppdFile);
+
+ $fh= fopen ($ppdFile, 'r');
+ while ((!feof($fh))&&($fh)) {
+
+ /* Read line */
+ $line= fgets($fh, 256);
+ if (strlen($line) >= 256){
+ trigger_error(_('Parsing PPD file %s failed - line too long. Trailing characters have been ignored'), E_USER_WARNING);
+ }
+
+ /* Extract interesting informations */
+ if (preg_match('/^\*Manufacturer:/i', $line)){
+ $manufacturer= preg_replace('/^\*Manufacturer:\s+"?([^"]+)"?.*$/i', '\1', $line);
+ }
+ if (preg_match('/^\*ModelName:/i', $line)){
+ $model= preg_replace('/^\*ModelName:\s+"?([^"]+)"?.*$/i', '\1', $line);
+ }
+
+ /* Got everything we need? Skip rest for speed reasons... */
+ if ($model != '' && $manufacturer != ''){
+ break;
+ }
+ }
+ fclose ($fh);
+
+ /* Write out a notice that the PPD file seems to be broken if we can't
+ extract any usefull informations */
+ if ($model == '' || $manufacturer == ''){
+ trigger_error(sprintf(_('Parsing PPD file %s failed - no information found.'), $ppdFile), E_USER_WARNING);
+ }
+
+ return ($manufacturer.' - '.$model);
+ }
+
+
+ function getPrinterList($reload= false)
+ {
+ /* Load list of PPD files */
+ if (count($this->cachedList) == 0 || $reload){
+ $list= $this->findPPD($this->path);
+
+ /* Load descriptive informations to build final printer list */
+ $new = array();
+ foreach ($list as $ppdFile){
+ $new[$ppdFile] = $this->loadDescription($ppdFile);
+ }
+ $this->cachedList= $new ;
+
+ }
+
+ return ($this->cachedList);
+ }
+
+}
+
+?>
diff --git a/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpPlugin.inc b/gosa-core/plugins/admin/systems/services/dhcp/class_dhcpPlugin.inc
--- /dev/null
@@ -0,0 +1,208 @@
+<?php
+/*
+ This code is part of GOsa (https://gosa.gonicus.de)
+ Copyright (C) 2003-2007 Cajus Pollmeier
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+class dhcpPlugin extends plugin
+{
+ /* Used attributes */
+ var $cn= "";
+ var $orig_cn= "";
+ var $options= array();
+ var $statements= array();
+
+ /* Subobjects */
+ var $network;
+ var $advanced;
+
+ /* attribute list for save action */
+ var $attributes= array();
+ var $objectclasses= array();
+
+ function dhcpPlugin($attrs)
+ {
+ /* Load statements / options */
+ if (is_array($attrs)){
+ $this->dn= $attrs['dn'];
+ $this->cn= $attrs['cn'][0];
+ $this->new= FALSE;
+
+ /* Load options */
+ if (isset($attrs['dhcpOption'])){
+ foreach ($attrs['dhcpOption'] as $opt){
+ $idx= preg_replace('/\s.+$/', '', $opt);
+ if ($idx == $opt){
+ $value= "";
+ } else {
+ $value= preg_replace('/^[^\s]+\s/', '', $opt);
+ }
+ $this->options[$idx]= $value;
+ }
+ }
+
+ /* Load statements */
+ if (isset($attrs['dhcpStatements'])){
+ foreach ($attrs['dhcpStatements'] as $opt){
+ $idx= preg_replace('/\s.+$/', '', $opt);
+ if ($idx == $opt){
+ $value= "";
+ } else {
+ $value= preg_replace('/^[^\s]+\s/', '', $opt);
+ }
+ $this->statements[$idx]= $value;
+ }
+ }
+
+ } else {
+ /* We keep the parent dn here if it's new */
+ $this->dn= $attrs;
+ $this->new= TRUE;
+ }
+
+ /* Load network module */
+ $this->network= new dhcpNetwork();
+ $this->network->options= $this->options;
+ $this->network->statements= $this->statements;
+ $this->advanced= new dhcpAdvanced();
+ $this->advanced->options= $this->options;
+ $this->advanced->statements= $this->statements;
+
+ /* Save CN for later reference */
+ $this->orig_cn= $this->cn;
+ }
+
+ function execute()
+ {
+ return ("");
+ }
+
+
+ function remove_from_parent()
+ {
+ }
+
+
+ /* Save data to object */
+ function save_object()
+ {
+ /* Strip network objects */
+ foreach (array("routers", "domain-name", "subnet-mask", "broadcast-address") as $toberemoved){
+ unset($this->options[$toberemoved]);
+ }
+ foreach (array("filename", "next-server") as $toberemoved){
+ unset($this->statements[$toberemoved]);
+ }
+
+ /* Save sub-objects */
+ $this->network->save_object();
+ $this->advanced->save_object();
+
+ /* Merge arrays for advanced view */
+ foreach (array("options", "statements") as $type){
+ $this->advanced->$type= $this->$type + $this->network->$type;;
+ }
+ }
+
+
+ /* Check values */
+ function check()
+ {
+ $message= array();
+ return $message;
+ }
+
+
+ /* Save to LDAP */
+ function save()
+ {
+ /* Merge arrays for network and advanced view */
+ foreach (array("options", "statements") as $type){
+ $this->$type= $this->$type + $this->network->$type + $this->advanced->$type;
+ }
+
+ /* Add cn if we're new */
+ if ($this->new){
+ $this->dn= "cn=".$this->cn.",".$this->dn;
+ } else {
+ $this->dn= "cn=".$this->cn.preg_replace('/^cn=[^,]+/', '', $this->dn);
+ }
+
+ /* Assemble new entry - options */
+ $this->attrs['dhcpOption']= array();
+ if (isset ($this->options) && count ($this->options)){
+ foreach ($this->options as $key => $val){
+ $this->attrs['dhcpOption'][]= "$key $val";
+ }
+ }
+
+ /* Assemble new entry - statements */
+ $this->attrs['dhcpStatements']= array();
+ if (isset ($this->statements) && count ($this->statements)){
+ foreach ($this->statements as $key => $val){
+ if ($val != ""){
+ $this->attrs['dhcpStatements'][]= "$key $val";
+ } else {
+ $this->attrs['dhcpStatements'][]= "$key";
+ }
+ }
+ }
+
+ /* Move dn to the result */
+ $this->attrs['dn']= $this->dn;
+ $this->attrs['cn']= array($this->cn);
+ $this->attrs['objectClass']= $this->objectclasses;
+ $this->attrs['MODIFIED']= TRUE;
+
+ return ($this->attrs);
+ }
+
+
+ function removeAttrs($name, $type)
+ {
+ $new= array();
+ foreach ($this->attrs[$type] as $value){
+ if (!preg_match("/^$name /", $value)){
+ $new[]= $value;
+ }
+ }
+ $this->attrs[$type]= $new;
+ }
+
+
+ function removeOption($name)
+ {
+ $this->removeAttrs($name, 'dhcpOption');
+ }
+
+
+ function removeStatement($name)
+ {
+ $this->removeAttrs($name, 'dhcpStatement');
+ }
+
+
+ function fix_options()
+ {
+ foreach (array('domain-name-servers') as $key){
+ unset ($this->options[$key]);
+ }
+ }
+
+}
+
+?>
diff --git a/gosa-core/plugins/admin/systems/services/glpi/class_glpi.inc b/gosa-core/plugins/admin/systems/services/glpi/class_glpi.inc
--- /dev/null
@@ -0,0 +1,1777 @@
+<?php
+
+
+class glpiDB{
+
+ var $user ="";
+ var $password ="";
+ var $server ="";
+ var $db ="";
+
+ var $is_connected = 0;
+ var $handle = NULL;
+
+ var $lasterror ="";
+
+ var $deviceMappingGOsaGlpi;
+ var $deviceMappingTableNameID;
+
+ function glpiDB($server,$user,$pwd,$db){
+ $this->server = $server;
+ $this->user = $user;
+ $this->password = $pwd;
+ $this->db = $db;
+
+ $this->handle = @mysql_connect($this->server,$this->user,$this->password);
+
+ if($this->handle){
+ $this->is_connected = true;
+ $this->SelectDB($this->db);
+ }
+ $this->deviceMappingGOsaGlpi = array(
+ "glpi_device_case" => "case",
+ "glpi_device_control" => "control",
+ "glpi_device_drive" => "drive",
+ "glpi_device_gfxcard" => "gfxcard",
+ "glpi_device_hdd" => "hdd",
+ "glpi_device_iface" => "iface",
+ "glpi_device_moboard" => "moboard",
+ "glpi_device_pci" => "pci",
+ "glpi_device_power" => "power",
+ "glpi_device_processor" => "processor",
+ "glpi_device_ram" => "ram",
+ "glpi_monitors" => "monitor",
+ "glpi_device_sndcard" => "sndcard");
+
+ $this->deviceMappingTableNameID = array( "moboard" => 1,
+ "processor" => 2,
+ "ram" => 3,
+ "hdd" => 4,
+ "iface" => 5,
+ "drive" => 6,
+ "control" => 7,
+ "gfxcard" => 8,
+ "sndcard" => 9,
+ "pci" => 10,
+ "case" => 11,
+ "power" => 12);
+
+
+ }
+
+ function SelectDB()
+ {
+ if($this->is_connected){
+ mysql_select_db($this->db,$this->handle);
+ }
+ }
+
+
+ /* This functions checks if the selected computer/network
+ device is already available in the db
+ */
+ function is_account($dn)
+ {
+ if(!$this->is_connected){
+ $this->lasterror ="Can't query anything, if we aren't connected.";
+ return(false);
+ }else{
+ $qry = "SELECT * FROM glpi_computers WHERE name='".$dn."';";
+ $res = $this->query($qry);
+ if(count($res)==0){
+ return(false);
+ }else{
+ return(true);
+ }
+ }
+ }
+
+ /* this function queries everything
+ */
+ function query($qry)
+ {
+ if(!$this->is_connected){
+ $this->lasterror ="Can't query anything, if we aren't connected.";
+ return(false);
+ }else{
+ $ret =array();
+ $res = mysql_query($qry,$this->handle);
+
+ while($rs = @mysql_fetch_array($res,MYSQL_ASSOC)){
+ $ret[]=$rs;
+ }
+ return($ret);
+ }
+ }
+
+ /* System types
+ Returns all defined system types
+ */
+ function getSystemTypes()
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp = ($this->query("SELECT * FROM glpi_type_computers;"));
+ foreach($tmp as $t){
+ $ret[$t['ID']]=$t['name'];
+ }
+ asort($ret);
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* System types
+ Update a system type
+ */
+ function updateSystemType($name,$id)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";");
+ if(isset($tmp[0])){
+ return($this->query("UPDATE glpi_type_computers SET name='".$name."' WHERE ID=".$id.";"));
+ }else{
+ echo "can't update not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* System types
+ Add one entry to the system types
+ */
+ function addSystemType($name)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE name='".$name."';");
+ if(isset($tmp[0])){
+ echo "such an entry already exists";
+ return(false);
+ }else{
+ return($this->query("INSERT INTO glpi_type_computers (name) VALUES ('".$name."');"));
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* System types
+ Remove one entry from the system types (specified by ID=$id)
+ */
+ function removeSystemType($id)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_type_computers WHERE ID=".$id.";");
+ if(isset($tmp[0])){
+ return($this->query("DELETE FROM glpi_type_computers WHERE ID=".$id.";"));
+ }else{
+ echo "can't remove not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* System type is used */
+ function is_systemTypeUsed($ID){
+ if($this->is_connected){
+ $ret = array();
+ $qry="SELECT name,type FROM glpi_computers WHERE type=".$ID." LIMIT 3;";
+ $res = $this->query($qry);
+ foreach($res as $val){
+ $ret[$val['name']] = $val['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+ /* Manufacturer
+ Returns all defined manufacturers
+ */
+ function getEnterprises()
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp = $this->query("SELECT * FROM glpi_enterprises ORDER BY name;");
+ foreach($tmp as $t){
+ $ret[$t['ID']]=$t['name'];
+ }
+
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Manufacturer
+ Returns single manufacturer
+ */
+ function getEnterprise($id)
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID=".$id.";");
+ return($tmp);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Manufacturer
+ Updates already existing manufacturer
+ */
+ function updateEnterprise($array,$id)
+ {
+ if(!is_array($array)){
+ echo "updateEnterprisesType: first paraeter must be an array";
+ }elseif($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID='".$id."';");
+ if(isset($tmp[0])){
+ $atr = array("ID","name","type","address","website","phonenumber","comments","deleted","fax","email");
+
+ $v = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $v .= " ".$at."='".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "updateEnterprisesType: no attributes given ";
+ return(false);
+ }else{
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("UPDATE glpi_enterprises SET ".$v." WHERE ID='".$id."';"));
+ }
+ }else{
+ echo "can't update not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Manufacturer
+ Add new manufacturer
+ */
+ function addEnterprise($array)
+ {
+ if(!is_array($array)){
+ echo "addUser: first paraeter must be an array";
+ }elseif($this->is_connected){
+ $atr = array("ID","name","type","address","website","phonenumber","comments","deleted","fax","email");
+ $v = "";
+ $a = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $a .= $at.", ";
+ $v .= "'".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "addUser: no attributes given ";
+ return(false);
+ }else{
+ $a = preg_replace("/, $/","",$a);
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("INSERT INTO glpi_enterprises (".$a.") VALUES (".$v.");"));
+ }
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ }
+
+ /* Manufacturer
+ remove manufacturer
+ */
+ function removeEnterprise($id)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_enterprises WHERE ID=".$id.";");
+ if(isset($tmp[0])){
+ return($this->query("DELETE FROM glpi_enterprises WHERE ID=".$id.";"));
+ }else{
+ echo "can't remove not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Operating systems
+ Returns all OSs
+ */
+ function getOSTypes($keys = false)
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp=($this->query("SELECT * FROM glpi_dropdown_os ORDER by name;"));
+
+ if($keys){
+ foreach($tmp as $t){
+ $ret[$t['name']]=$t['ID'];
+ }
+ }else{
+ foreach($tmp as $t){
+ $ret[$t['ID']]=$t['name'];
+ }
+ }
+ return($ret);
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Operating system is used ? */
+ function is_osUsed($ID){
+ if($this->is_connected){
+ $ret = array();
+ $qry="SELECT name,type FROM glpi_computers WHERE os=".$ID." LIMIT 3;";
+ $res = $this->query($qry);
+ foreach($res as $val){
+ $ret[$val['name']] = $val['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+ /* Operating systems
+ Add a new operating system to the dropdown menus
+ */
+ function addOS($name)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE name='".$name."';");
+ if(isset($tmp[0])){
+ echo "such an entry already exists";
+ return(false);
+ }else{
+ return($this->query("INSERT INTO glpi_dropdown_os (name) VALUES ('".$name."');"));
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Operating systems
+ remove one OS entry
+ */
+ function removeOS_byID($id)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";");
+ if(is_array($tmp[0])){
+ return($this->query("DELETE FROM glpi_dropdown_os WHERE ID=".$id.";"));
+ }else{
+ echo "can't remove not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Operating systems
+ Update existing OS entry
+ */
+ function updateOS($name,$id)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_dropdown_os WHERE ID=".$id.";");
+ if(isset($tmp[0])){
+ return($this->query("UPDATE glpi_dropdown_os SET name='".$name."' WHERE ID=".$id.";"));
+ }else{
+ echo "can't update not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* This returns all available glpi users
+ */
+ function getUsers()
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp = ($this->query("SELECT * FROM glpi_users"));
+ foreach($tmp as $user){
+ $ret[$user['ID']]=$user['name'];
+ }
+ return($ret);
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* this function adds a new glpi user
+ */
+ function addUser($array,$dn)
+ {
+ if(!is_array($array)){
+ echo "addUser: first paraeter must be an array";
+ }elseif($this->is_connected){
+ $array['name']=$dn;
+ $atr = array("name","phone","email");
+ $v = "";
+ $a = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $a .= $at.", ";
+ $v .= "'".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "addUser: no attributes given ";
+ return(false);
+ }else{
+ $a = preg_replace("/, $/","",$a);
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("INSERT INTO glpi_users (".$a.") VALUES (".$v.");"));
+ }
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ }
+
+ /* This function updates a glpi user
+ with the given data
+ */
+ function updateUser($array,$dn)
+ {
+ if(!is_array($array)){
+ echo "updateUser: first paraeter must be an array";
+ }elseif($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_users WHERE name='".$dn."';");
+ if(isset($tmp[0])){
+
+ $atr = array("name","phone","email");
+ $v = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $v .= " ".$at."='".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "UpdateUser: no attributes given ";
+ return(false);
+ }else{
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("UPDATE glpi_users SET ".$v." WHERE name='".$dn."';"));
+ }
+ }else{
+ echo "can't update not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ }
+
+ /* This function returns all available data
+ from a specified dn
+ */
+ function getComputerInformations($name)
+ {
+ if($this->is_connected){
+ $ret = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* This fucntions updates an already existing entry
+ */
+ function updateComputerInformations($array,$name)
+ {
+ if(!is_array($array)){
+ echo "updateComputerInformations: first paraeter must be an array";
+ }elseif($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
+ if(isset($tmp[0])){
+
+ $atr = array( "ID","name","serial","otherserial","contact","contact_num",
+ "tech_num","comments","date_mod","os","location","domain","network",
+ "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
+ $v = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $v .= " ".$at."='".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "updateComputerInformations: no attributes given ";
+ return(false);
+ }else{
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("UPDATE glpi_computers SET ".$v." WHERE name='".$name."';"));
+ }
+ }else{
+ echo "can't update not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ }
+
+ /* This function adds a new inventory device (computer phone etc)
+ */
+ function addComputerInformations($array)
+ {
+ if(!is_array($array)){
+ echo "updateComputerInformations: first paraeter must be an array";
+ }elseif($this->is_connected){
+ $atr = array( "ID","name","serial","otherserial","contact","contact_num",
+ "tech_num","comments","date_mod","os","location","domain","network",
+ "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
+ $v = "";
+ $a = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $a .= $at.", ";
+ $v .= "'".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "updateComputerInformations: no attributes given ";
+ return(false);
+ }else{
+ $a = preg_replace("/, $/","",$a);
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("INSERT INTO glpi_computers (".$a.") VALUES (".$v.");"));
+ }
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ }
+
+ /* this functions checks if the given Device
+ * already exists
+ */
+ function deviceExists($attr)
+ {
+ $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
+ if($this->is_connected){
+ $arr = array_flip($deviceMappingGOsaGlpi);
+
+ $tbl_name = $arr[$attr['device_type']];
+ if(!isset($attr['ID'])){
+ return(false);
+ }else{
+ $qry = "SELECT * FROM ".$tbl_name." WHERE ID=".$attr['ID'].";";
+ $res = $this->query($qry);
+ if(count($res) != 0){
+ return(true);
+ }
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ return(false);
+ }
+
+
+ /* Check if given device is used by some accounts
+ * (helpfull to avoid removement of used devices)
+ */
+ function is_deviceUsed($item)
+ {
+ $deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
+ $deviceMappingTableNameID = $this->deviceMappingTableNameID;
+ if($this->is_connected){
+ $tablename = $deviceMappingGOsaGlpi[$item['device_type']];
+ $type = $item['device_type'];
+
+ $ret = array();
+
+ if($type=="monitor"){
+ $str = "SELECT c.name FROM glpi_connect_wire as w, glpi_computers as c WHERE w.end1=".$item['ID']." AND w.end2 = c.ID AND w.type=4;";
+ }else{
+ $str = "SELECT c.name FROM glpi_computer_device as d, glpi_computers as c WHERE d.FK_computers=c.ID AND FK_device=".$item['ID']." AND device_type=".$deviceMappingTableNameID[$type]." ;";
+ }
+
+ $res = $this->query($str);
+
+ foreach($res as $val){
+ $ret[$val['name']] = $val['name'];
+ }
+
+ return($ret);//count($this->query($str)));
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ }
+
+
+ /* This functions deletes a specified entry
+ * from our device tables
+ */
+ function deleteDevice($attr)
+ {
+ $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
+ if($this->is_connected){
+ $arr = array_flip($deviceMappingGOsaGlpi);
+
+ $device_type = $attr['device_type'];
+ unset($attr['device_type']);
+
+ $tbl_name = $arr[$device_type];
+
+ $this->query("DELETE FROM ".$tbl_name." WHERE ID=".$attr['ID'].";");
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* This funtions updated an already existing device
+ */
+ function updateDevices($attr)
+ {
+ $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
+ if($this->is_connected){
+ $arr = array_flip($deviceMappingGOsaGlpi);
+
+ $device_type = $attr['device_type'];
+ unset($attr['device_type']);
+
+ $tbl_name = $arr[$device_type];
+
+ $str = "UPDATE ".$tbl_name." SET ";
+ foreach($attr as $name => $value){
+ $str.=$name."='".$value."', ";
+ }
+ $str = preg_replace("/, $/","",$str);
+ $str .= " WHERE ID=".$attr['ID'].";";
+ $this->query($str);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Returns all possible RAM types
+ * like SDRAM , DIMM .....
+ */
+ function getRAMTypes()
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp = ($this->query("SELECT * FROM glpi_dropdown_ram_type;"));
+ foreach($tmp as $t){
+ $ret[$t['ID']]=$t['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Returns all possible HDD connection types
+ * like IDE SCSI ...
+ */
+ function getGlpiDeviceControlTypes()
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp = ($this->query("SELECT * FROM glpi_dropdown_hdd_type;"));
+ foreach($tmp as $t){
+ $ret[$t['ID']]=$t['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Returns all possible gfx card connection types
+ * like PCI-X PCI AGP ....
+ */
+ function getGlpiGfxControlTypes()
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp = ($this->query("SELECT * FROM glpi_dropdown_hdd_type;"));
+ foreach($tmp as $t){
+ $ret[$t['ID']]=$t['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Devices
+ Adds a new single device to our db
+ */
+ function addDevice($attr)
+ {
+ $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
+ if($this->is_connected){
+ $arr = array_flip($deviceMappingGOsaGlpi);
+
+ $device_type = $attr['device_type'];
+ unset($attr['device_type']);
+
+ $tbl_name = $arr[$device_type];
+ $v = "";
+ $a = "";
+ foreach($attr as $name => $value){
+ $a .= $name.", ";
+ $v .= "'".$value."', ";
+ }
+ if(empty($v)){
+ echo "addDevice: no attributes given ";
+ return(false);
+ }else{
+ $a = preg_replace("/, $/","",$a);
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("INSERT INTO ".$tbl_name." (".$a.") VALUES (".$v.");"));
+ }
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Return all available devices
+ */
+ function getDevices()
+ {
+ $deviceMappingGOsaGlpi = $this->deviceMappingGOsaGlpi;
+ if($this->is_connected){
+ $arr = $deviceMappingGOsaGlpi;
+
+ $res = array();
+ foreach($arr as $glpi => $gosa){
+ $qry = "SELECT * FROM ".$glpi.";";
+ $ret = $this->query($qry);
+ foreach($ret as $id => $entry){
+ $entry['device_type'] = $gosa;
+
+ if(isset($entry['designation'])){
+ $res[$entry['designation']."-".$gosa] = $entry;
+ }else{
+ $res[$entry['name']."-".$gosa] = $entry;
+ }
+ }
+ }
+ return($res);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* This function returns all used devices
+ */
+ function getUsedDevices($computerID)
+ {
+ $deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
+ $deviceMappingTableNameID = $this->deviceMappingTableNameID;
+
+ if($this->is_connected){
+ $qry = "SELECT * FROM glpi_computer_device WHERE FK_computers=".$computerID.";";
+ $res = $this->query($qry);
+
+ $ret = array();
+ foreach($deviceMappingGOsaGlpi as $GOsa => $glpi){
+ $ret[$GOsa] = array();
+ }
+
+ $tbls = array_flip($deviceMappingTableNameID);
+
+ foreach($res as $device){
+ $devtype = $tbls[$device['device_type']];
+ $tbl_name = $deviceMappingGOsaGlpi[$devtype];
+ $qry = ("SELECT * FROM ".$tbl_name." WHERE ID=".$device['FK_device'].";");
+ $res2 = $this->query($qry);
+ if(count($res2)!=0){
+ $ret[$devtype][$res2[0]['designation']]=$res2[0];
+ }
+
+ $qry = "SELECT * FROM glpi_connect_wire WHERE type=4 AND end2=".$computerID.";";
+ $res2 = $this->query($qry);
+ foreach($res2 as $monitor){
+ $qry = "SELECT * FROM glpi_monitors WHERE ID=".$monitor['end1'].";";
+ $res3 = $this->query($qry);
+ foreach($res3 as $moni){
+ $ret['monitor'][$moni['name']]=$moni;
+ }
+ }
+
+
+
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* This function removes all given devices from a computer, specified by $id
+ In the next step all devices specified by devices will be added.
+ */
+ function addDevicesToComputer($devices, $id)
+ {
+ $deviceMappingGOsaGlpi = array_flip($this->deviceMappingGOsaGlpi);
+ $deviceMappingTableNameID = $this->deviceMappingTableNameID;
+
+ if(($id == "" )||(!is_numeric($id))){
+ return (false);
+ }
+ if($this->is_connected){
+ $qry = "DELETE FROM glpi_computer_device WHERE FK_computers=".$id.";";
+ $this->query($qry);
+
+ foreach($devices as $type => $entries){
+ foreach($entries as $entry){
+ if($type=="monitor"){
+ $str = "INSERT INTO glpi_connect_wire (end1,end2,type)
+ VALUES (".$entry['ID'].",".$id.",4);";
+ }else{
+ $str = "INSERT INTO glpi_computer_device (device_type,FK_device,FK_computers)
+ VALUES (".$deviceMappingTableNameID[$type].",".$entry['ID'].",".$id.");";
+ }
+ $this->query($str);
+ }
+ }
+
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ }
+
+ function removeComputerInformations($name)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_computers WHERE name='".$name."';");
+ if(isset($tmp[0])){
+ $id = $tmp[0]['ID'];
+ $this->query("DELETE FROM glpi_connect_wire WHERE end2=".$id.";");
+ $this->query("DELETE FROM glpi_computer_device WHERE FK_computers=".$id.";");
+ return($this->query("DELETE FROM glpi_computers WHERE ID=".$id.";"));
+ }else{
+ echo "can't remove not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function is_connected()
+ {
+ return($this->is_connected);
+ }
+
+ function addAttachmentsToComputer($attr,$id)
+ {
+ if(($id == "" )||(!is_numeric($id))){
+ return (false);
+ }
+ if($this->is_connected){
+ $qry = "DELETE FROM glpi_doc_device WHERE (FK_device=".$id.") AND (device_type=1);";
+ $this->query($qry);
+
+ foreach($attr as $aid => $entry){
+ $str = "INSERT INTO glpi_doc_device (FK_doc,FK_device,device_type,is_template)
+ VALUES
+ ($aid,$id,1,'0');";
+ $this->query($str);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getAssignAttachments($id)
+ {
+
+ if($this->is_connected){
+ $qry= "SELECT * FROM glpi_doc_device WHERE (device_type=1) AND (FK_device=".$id.");";
+ $ret = $this->query($qry);
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function deleteAttachment($id)
+ {
+ if($this->is_connected){
+ $qry = "DELETE FROM glpi_docs WHERE ID=".$id."";
+ $this->query($qry);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getAttachments()
+ {
+ $ret = array();
+ if($this->is_connected){
+ $qry = "SELECT * FROM glpi_docs WHERE name!='';";
+ $re = $this->query($qry);
+
+ foreach($re as $entry){
+ $ret[$entry['ID']]=$entry;
+ }
+
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function saveAttachments($attrs,$id = -1)
+ {
+ if($this->is_connected){
+ $atr = array("name","filename","rubrique","mime","date_mod","comment","deleted","link");
+ $tmp = array();
+ foreach($atr as $at){
+ if(isset($attrs[$at])){
+ $tmp[$at] = $attrs[$at];
+ }
+ }
+ if(count($tmp)==0){
+ return(false);
+ }else{
+
+ // Add
+ if($id == -1){
+ $str = "INSERT INTO glpi_docs ";
+ $namen = "";
+ $values= "";
+ foreach($tmp as $name => $value){
+ $namen .= $name.", ";
+ if(is_numeric($value)){
+ $values .= $value.", ";
+ }else{
+ $values .= "'".$value."', ";
+ }
+ }
+ $values = preg_replace("/, $/","",$values);
+ $namen = preg_replace("/, $/","",$namen);
+ $str .= "(".$namen.") VALUES (".$values.");";
+ }else{
+ $str = "UPDATE glpi_docs SET ";
+ foreach($tmp as $name => $value){
+ $str .= $name."= ";
+ if(is_numeric($value)){
+ $str .= $value.", ";
+ }else{
+ $str .= "'".$value."', ";
+ }
+ }
+ $str = preg_replace("/, $/","",$str);
+ $str .= " WHERE ID=".$id.";";
+ }
+ $this->query($str);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+ /* Check if given attachment id is used in any Device
+ ( - avoid removing of used attachments)
+ */
+ function is_attachmentUsed($id)
+ {
+ if($this->is_connected){
+ $ret = array();
+ $qry = "SELECT t.name FROM glpi_computers as t, glpi_doc_device WHERE t.ID = glpi_doc_device.FK_device AND FK_doc =".$id." LIMIT 3;";
+ $res = $this->query($qry);
+ foreach($res as $val){
+ $ret[$val['name']] = $val['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+ /* Monitor handling
+ */
+ function getMonitors()
+ {
+ if($this->is_connected){
+ $qry= "SELECT * FROM glpi_monitors;";
+ return($this->query($qry));
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function updatedMonitor()
+ {
+ if($this->is_connected){
+// $qry= "SELECT * FROM glpi_monitors;";
+// return($this->query($qry));
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function addMonitor()
+ {
+ if($this->is_connected){
+// $qry= "SELECT * FROM glpi_monitors;";
+// return($this->query($qry));
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function removeMonitor($id)
+ {
+ if($this->is_connected){
+ $qry= "DELETE FROM glpi_monitors WHERE ID=".$id.";";
+ $this->query($qry);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getMonitorTypes()
+ {
+ if($this->is_connected){
+ $qry= "SELECT * FROM glpi_type_monitors;";
+ return($this->query($qry));
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getLocationTypes()
+ {
+ if($this->is_connected){
+ $qry= "SELECT * FROM glpi_dropdown_locations;";
+ return($this->query($qry));
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getStateTypes()
+ {
+ if($this->is_connected){
+ $qry= "SELECT * FROM glpi_dropdown_state;";
+ return($this->query($qry));
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+ /* Printer functions
+ */
+
+ /* is printer type used ?
+ */
+ function is_printerTypeUsed($id)
+ {
+ if($this->is_connected){
+ $qry = "SELECT * FROM glpi_printers WHERE type=".$id.";";
+ $res = $this->query( $qry);
+ $ret =array();
+ foreach($res as $entry){
+ $ret[$entry['ID']] = $entry['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* This functions checks if the selected computer/network
+ device is already available in the db
+ */
+ function is_printer_account($dn)
+ {
+ if(!$this->is_connected){
+ $this->lasterror ="Can't query anything, if we aren't connected.";
+ return(false);
+ }else{
+ $qry = "SELECT * FROM glpi_printers WHERE name='".$dn."';";
+ $res = $this->query($qry);
+ if(count($res)==0){
+ return(false);
+ }else{
+ return(true);
+ }
+ }
+ }
+
+ /* This function returns all available data
+ from a specified dn
+ */
+ function getPrinterInformations($name)
+ {
+ if($this->is_connected){
+ $ret = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Get Printer attachments
+ */
+ function getAssignPrinterAttachments($id)
+ {
+
+ if($this->is_connected){
+ $qry= "SELECT * FROM glpi_doc_device WHERE (device_type=3) AND (FK_device=".$id.");";
+ $ret = $this->query($qry);
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Printer types
+ Returns all defined printer types
+ */
+ function getPrinterTypes()
+ {
+ if($this->is_connected){
+ $ret = array();
+ $tmp = ($this->query("SELECT * FROM glpi_type_printers ORDER BY name; "));
+ foreach($tmp as $t){
+ $ret[$t['ID']]=$t['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Add pritner types
+ Add one entry to the printer types
+ */
+ function addPrinterType($name)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_type_printers WHERE name='".$name."';");
+ if(isset($tmp[0])){
+ //echo "such an entry already exists";
+ return(false);
+ }else{
+ return($this->query("INSERT INTO glpi_type_printers (name) VALUES ('".$name."');"));
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* remove printer types
+ Remove one entry from the printer types (specified by ID=$id)
+ */
+ function removePrinterType($id)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_type_printers WHERE ID=".$id.";");
+ if(isset($tmp[0])){
+ return($this->query("DELETE FROM glpi_type_printers WHERE ID=".$id.";"));
+ }else{
+ echo "can't remove not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Update printer types
+ Update a printer type
+ */
+ function updatePrinterType($name,$id)
+ {
+
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_type_printers WHERE ID=".$id.";");
+ if(isset($tmp[0])){
+ return($this->query("UPDATE glpi_type_printers SET name='".$name."' WHERE ID=".$id.";"));
+ }else{
+ echo "can't update not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+ /* This fucntions updates an already existing entry
+ */
+ function updatePrinterInformations($array,$name)
+ {
+ if(!is_array($array)){
+ echo "updatePrinterInformations: first paraeter must be an array";
+ }elseif($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
+ if(isset($tmp[0])){
+
+ $atr = array( "ID","name","serial","otherserial","contact","contact_num",
+ "tech_num","comments","date_mod","location","domain","network","ramSize","flags_serial","flags_par","flags_usb",
+ "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
+ $v = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $v .= " ".$at."='".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "updateSystemInformations: no attributes given ";
+ return(false);
+ }else{
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("UPDATE glpi_printers SET ".$v." WHERE name='".$name."';"));
+ }
+ }else{
+ echo "can't update not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+
+ }
+
+ /* This function adds a new inventory settings for printers
+ */
+ function addPrinterInformations($array)
+ {
+ if(!is_array($array)){
+ echo "updateComputerInformations: first paraeter must be an array";
+ }elseif($this->is_connected){
+ $atr = array( "ID","name","serial","otherserial","contact","contact_num",
+ "tech_num","comments","date_mod","os","location","domain","network","ramSize","flags_serial","flags_par","flags_usb",
+ "model","type","is_template","tplname","FK_glpi_enterprise","deleted");
+ $v = "";
+ $a = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $a .= $at.", ";
+ $v .= "'".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "updateComputerInformations: no attributes given ";
+ return(false);
+ }else{
+ $a = preg_replace("/, $/","",$a);
+ $v = preg_replace("/, $/","",$v);
+ return($this->query("INSERT INTO glpi_printers (".$a.") VALUES (".$v.");"));
+ }
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* add atachment to given printer */
+ function addAttachmentsToPrinter($attr,$id)
+ {
+ if(($id == "" )||(!is_numeric($id))){
+ return (false);
+ }
+ if($this->is_connected){
+ $qry = "DELETE FROM glpi_doc_device WHERE (FK_device=".$id.") AND (device_type=3);";
+ $this->query($qry);
+
+ foreach($attr as $aid => $entry){
+ $str = "INSERT INTO glpi_doc_device (FK_doc,FK_device,device_type,is_template)
+ VALUES
+ ($aid,$id,3,'0');";
+ $this->query($str);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function removePrinterInformations($name)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_printers WHERE name='".$name."';");
+ if(isset($tmp[0])){
+ $id = $tmp[0]['ID'];
+// $this->query("DELETE FROM glpi_connect_wire WHERE end2=".$id.";");
+ $this->query("DELETE FROM glpi_doc_device WHERE FK_device=".$id." AND device_type=3;");
+ return($this->query("DELETE FROM glpi_printers WHERE ID=".$id.";"));
+ }else{
+ echo "can't remove not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+ /* Cartridges
+ */
+ /* return all assigned cartridges */
+ function getUsedCartridges($printerID)
+ {
+ if($this->is_connected){
+ $ret = array();
+ $qry = "SELECT
+ c.date_use as date_use,
+ c.ID as ID,
+ t.ID as type_ID,
+ t.name as name,
+ c.FK_glpi_printers as FK_glpi_printers,
+ d.name as type_name
+ FROM
+ glpi_dropdown_cartridge_type as d,
+ glpi_cartridges as c,
+ glpi_cartridges_type as t
+ WHERE c.FK_glpi_cartridges_type = t.ID
+ AND t.type = d.ID
+ AND c.FK_glpi_printers = ".$printerID.";";
+ $res = $this->query($qry);
+ foreach($res as $entry){
+ $ret[$entry['ID']] = $entry;
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* return all assigned cartridges */
+ function getAvailableCartridgeTypes($printerTypeID)
+ {
+ if($this->is_connected){
+ $ret = array();
+ $qry= "
+ SELECT
+ ct.ID as cartridgeID,
+ ct.name as cartridgeName,
+ pt.ID as printerTypeID,
+ pt.name as printerTypeName,
+ ct.type as cartridgeTypeID,
+ dt.name as cartridgeTypeName
+ FROM
+ glpi_type_printers as pt,
+ glpi_cartridges_type as ct,
+ glpi_dropdown_cartridge_type as dt,
+ glpi_cartridges_assoc as ac
+ WHERE
+ ac.FK_glpi_type_printer = pt.ID
+ AND ac.FK_glpi_cartridges_type = ct.ID
+ AND ct.type=dt.ID
+ AND pt.ID=".$printerTypeID.";";
+ $res = $this->query($qry);
+ foreach($res as $entry){
+ $ret[$entry['cartridgeID']] = $entry;
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function removeCartridgeFromPrinter($cartridgeID)
+ {
+ if($this->is_connected){
+ $qry = "DELETE FROM glpi_cartridges WHERE ID=".$cartridgeID.";";
+ return($this->query($qry));
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function addCartridgeFromPrinter($printerID,$cartridgeID)
+ {
+ if($this->is_connected){
+ $qry ="INSERT INTO
+ glpi_cartridges (FK_glpi_cartridges_type,FK_glpi_printers,date_in,date_use)
+ VALUES
+ (".$cartridgeID.",".$printerID.",'".date("Y-m-d")."','".date("Y-m-d")."');";
+ return($this->query($qry));
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function is_cartridgeTypeUsed($id){
+ if($this->is_connected){
+ $qry = "SELECT p.ID,p.name as name FROM glpi_cartridges as c,glpi_printers as p WHERE p.ID=c.FK_glpi_printers AND c.FK_glpi_cartridges_type=".$id.";";
+ $res = $this->query($qry);
+ $ret =array();
+ foreach($res as $entry){
+ $ret[$entry['ID']] = $entry['name'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getCartridgeTypeInformations($id = "all"){
+ if($this->is_connected){
+ $ret = array();
+ if($id != "all"){
+ $qry = "SELECT * FROM glpi_cartridges_type WHERE ID = ".$id.";";
+ }else{
+ $qry = "SELECT * FROM glpi_cartridges_type;";
+ }
+
+ $res = ($this->query($qry));
+ foreach($res as $entry){
+ $ret[$entry['ID']] = $entry;
+ }
+ return($ret);
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getCartridgeTypes(){
+ if($this->is_connected){
+ $ret = array();
+ $qry = "SELECT * FROM glpi_dropdown_cartridge_type;";
+ $res = ($this->query($qry));
+ foreach($res as $entry){
+ $ret[$entry['ID']] = $entry['name'];
+ }
+ return($ret);
+
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+
+ /* check if given manufacturer ID ist still in use.
+ The problem is, that nearly every table uses manufacturers ....
+ */
+ function is_manufacturerUsed($id)
+ {
+ if($this->is_connected){
+ $tables = array();
+ foreach($this->deviceMappingGOsaGlpi as $entry => $table){
+ $tables[] = $entry;
+ }
+ $tables[] ="glpi_computers";
+ $tables[] ="glpi_cartridges_type";
+ $ret = array();
+ $i = 3;
+ foreach($tables as $tbl){
+ if($i <= 0 ) continue;
+ $qry = "SELECT * FROM ".$tbl." WHERE FK_glpi_enterprise = ".$id.";";
+ $res = $this->query($qry);
+ foreach($res as $entry){
+ if($i <= 0 ) continue;
+ if(isset($entry['designation'])){
+ $entry['name'] = $entry['designation'];
+ }
+ $i --;
+ $ret[] = $entry['name'];
+ }
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Manufacturer
+ Updates already existing manufacturer
+ */
+ function Add_UpdateCatrigdeType($array,$array_printer_types)
+ {
+ if(!is_array($array)){
+ echo "Add_UpdateCatrigdeType: first paraeter must be an array";
+ }elseif($this->is_connected){
+
+
+ $atr = array("name","ref","location","type","FK_glpi_enterprise","tech_num","deleted","comments","alarm");
+
+ /* Entry was edited */
+ if($array['ID']>0){
+ $qry = "DELETE FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type=".$array['ID'].";";
+
+ $v = "";
+ foreach($atr as $at){
+ if(isset($array[$at])){
+ $v .= " ".$at."='".$array[$at]."', ";
+ }
+ }
+ if(empty($v)){
+ echo "Add_UpdateCatrigdeType: no attributes given ";
+ return(false);
+ }else{
+ $v = preg_replace("/, $/","",$v);
+ $qry = "UPDATE glpi_cartridges_type SET ".$v." WHERE ID='".$array['ID']."';";
+ $this->query($qry);
+ }
+ }else{
+
+ /* skip if name is in use*/
+ $qry = "SELECT * FROM glpi_cartridges_type WHERE name='".$array['name']."';";
+ if(count($this->query($qry))){
+ return;
+ }
+
+ $str = "INSERT INTO glpi_cartridges_type ";
+ $namen = "";
+ $values= "";
+ foreach($array as $name => $value){
+ $namen .= $name.", ";
+ if(is_numeric($value)){
+ $values .= $value.", ";
+ }else{
+ $values .= "'".$value."', ";
+ }
+ }
+ $values = preg_replace("/, $/","",$values);
+ $namen = preg_replace("/, $/","",$namen);
+ $str .= "(".$namen.") VALUES (".$values.");";
+ $this->query($str);
+ $IDs = $this->query("SELECT ID FROM glpi_cartridges_type WHERE name='".$array['name']."';");
+ if(count($IDs) > 1){
+ echo "internal db error";
+ return;
+ }
+ $array['ID'] = $IDs[0]['ID'];
+ }
+
+ foreach($array_printer_types as $id){
+ $qry = "INSERT INTO glpi_cartridges_assoc
+ (FK_glpi_cartridges_type,FK_glpi_type_printer)
+ VALUES
+ (".$array['ID'].",".$id.")";
+
+ $this->query($qry);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getSupportedPrinterTypeIDsForCartridge($cid)
+ {
+ if($this->is_connected){
+ $ret = array();
+ $qry = "SELECT FK_glpi_type_printer FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type = ".$cid.";";
+ $res = $this->query($qry);
+
+ foreach($res as $entry => $value){
+ $ret[$value['FK_glpi_type_printer']] = $value['FK_glpi_type_printer'];
+ }
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function removeCartridgeType($id){
+ if($this->is_connected){
+ $qry = "DELETE FROM glpi_cartridges_assoc WHERE FK_glpi_cartridges_type=".$id.";";
+ $this->query($qry);
+ $qry = "DELETE FROM glpi_cartridges_type WHERE ID=".$id.";";
+ return($this->query($qry));
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getCartridgesWhichUseThisType($id)
+ {
+ if($this->is_connected){
+ $qry = "SELECT * FROM glpi_cartridges WHERE FK_glpi_cartridges_type=".$id.";";
+ $ret = $this->query($qry);
+ return($ret);
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+
+ /* Add pritner types
+ Add one entry to the cartridgeType types
+ */
+ function addCartridgeDropdownType($name)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE name='".$name."';");
+ if(isset($tmp[0])){
+ //echo "such an entry already exists";
+ return(false);
+ }else{
+ return($this->query("INSERT INTO glpi_dropdown_cartridge_type (name) VALUES ('".$name."');"));
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* remove cartridgeType types
+ Remove one entry from the cartridgeType types (specified by ID=$id)
+ */
+ function removeCartridgeDropdownType($id)
+ {
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";");
+ if(isset($tmp[0])){
+ return($this->query("DELETE FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";"));
+ }else{
+ echo "can't remove not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ /* Update cartridgeType
+ Update a cartridgeType
+ */
+ function updateCartridgeDropdownType($name,$id)
+ {
+
+ if($this->is_connected){
+ $tmp = $this->query("SELECT * FROM glpi_dropdown_cartridge_type WHERE ID=".$id.";");
+ if(isset($tmp[0])){
+ return($this->query("UPDATE glpi_dropdown_cartridge_type SET name='".$name."' WHERE ID=".$id.";"));
+ }else{
+ echo "can't update not existing entry";
+ return(false);
+ }
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+ function getUsedDropdownTypes($id=false)
+ {
+ if($this->is_connected){
+ if($id){
+ $qry = "SELECT distinct(type) FROM glpi_cartridges_type WHERE type = ".$id.";";
+ }else{
+ $qry = "SELECT distinct(type) FROM glpi_cartridges_type;";
+ }
+ return($this->query($qry));
+ }else{
+ echo "not connected";
+ return(false);
+ }
+ }
+
+}
+//$s = new glpiDB("vserver-01","glpi","tester","glpi");
+//print_r($s->query("SELECT * FROM glpi_computers"));
+//$s->getComputerInformations("1 OR (c.ID<10000)");
+?>
diff --git a/gosa-core/plugins/personal/connectivity/class_opengw.inc b/gosa-core/plugins/personal/connectivity/class_opengw.inc
--- /dev/null
@@ -0,0 +1,547 @@
+<?php
+
+require_once("class_pgsql_opengw.inc");
+
+class ogw{
+ var $info;
+ var $ogo;
+
+ var $validLocationTeam;
+ var $validTemplateUser;
+ var $validTeams;
+
+
+ var $InfoOK = false;
+
+ var $MUST = array("name","login","template_user_id");
+
+ var $MAY = array( "salutation","firstname","description","degree",
+ "birthday","sex","street","zip","country","zipcity",
+ "state","name1","value_string","number","db_status",
+ "object_version","is_locked","LocationTeamID","TeamIDis","password");
+
+ var $LastError = "";
+ var $option = "";
+ var $connected = false;
+
+ function ogw($username,$password,$host,$db)
+ {
+ $this->ogo = new pgre_sql($username,$password,$host,$db);
+
+ if($this->ogo->is_connected){
+ $this->validLocationTeam = $this->ogo->GetLocationTeam();
+ $this->validTemplateUser = $this->ogo->GetTemplateUser();
+ $this->validTeams = $this->ogo->GetTeams();
+ $this->connected = true;
+ }else{
+ $this->validLocationTeam = array();//$this->ogo->GetLocationTeam();
+ $this->validTemplateUser = array();//$this->ogo->GetTemplateUser();
+ $this->validTeams = array();//$this->ogo->GetTeams();
+ $this->connected = false;
+ }
+ }
+
+ function SetInfos($infos)
+ {
+ if(isset($infos['name'])) {
+ $infos['name1'] = $infos['name'];
+ }
+ $this->info = $infos;
+ }
+
+ function GetInfos($uid)
+ {
+ $ret = array();
+ $qry = "SELECT is_person,is_account,is_intra_account,is_extra_account,
+ number,owner_id,object_version,company_id,template_user_id,is_locked,
+ name,firstname,description,salutation,login,degree,birthday,sex
+ FROM person WHERE login='".$uid."';";
+ $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+ $ret = $res[0];
+
+ $qry = "SELECT street,zip,zipcity,country,state FROM address WHERE company_id = ".$ret['company_id']." limit 1;";
+ $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+ $ret = array_merge($ret,$res[0]);
+
+ $qry = "SELECT company_id FROM company_assignment
+ WHERE (sub_company_id=".$ret['company_id'].")
+ AND company_id IN
+ (SELECT company_id FROM team WHERE (is_team=1)
+ AND
+ company_id NOT IN (SELECT company_id FROM team WHERE is_location_team=1));";
+ $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+ if(is_array($res)){
+ foreach($res as $r){
+ $ret['TeamIDis'][]=$r['company_id'];
+ }
+ }else{
+ $ret['TeamIDis']=array();
+ }
+
+ $qry = "SELECT value_string from company_value WHERE company_id=".$ret['company_id'].";";
+ $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+ $ret = array_merge($ret,$res[0]);
+
+ $qry ="SELECT company_id FROM company_assignment
+ WHERE (sub_company_id=".$ret['company_id'].")
+ AND company_id IN (SELECT company_id FROM team WHERE (is_location_team=1));";
+ $res = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+ $ret['LocationTeamID'] = $res[0]['company_id'];
+
+ return($ret);
+ }
+
+ function Perform($option)
+ {
+ if(!in_array($option,array("ADD","EDIT","REMOVE"))){
+ $this->LastError = sprintf("Option '%s' is not allowed, possible options are 'ADD' 'EDIT' 'REMOVE'.",$option);
+ return(false);
+ }else{
+ $this->option = $option;
+ if(($this->option == "EDIT")||($this->option=="ADD")){
+
+ /* Static variables */
+ if(!isset($this->info['is_person'])){
+ $this->info['is_person'] = 1;
+ }
+
+ if(!isset($this->is_account)){
+ $this->info['is_account'] = 1;
+ }
+
+ if(!isset($this->info['is_intra_account'])){
+ $this->info['is_intra_account'] = 1;
+ }
+
+ if(!isset($this->info['is_extra_account'])){
+ $this->info['is_extra_account'] = 0;
+ }
+
+ if(!isset($this->info['owner_id'])){
+ $this->info['owner_id'] = 10000;
+ }
+
+ if(!isset($this->info['is_team'])){
+ $this->info['is_team'] = 0;
+ }
+
+ $this->InfoOK = $this->checkInfos();
+
+ if($this->InfoOK){
+ $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
+ $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+
+ if($this->option == "ADD"){
+ if($this->CheckExistence()){
+ $this->LastError="Can't add entry already exists.";
+ return(false);
+ }else{
+ $this->info['db_status'] = "inserted";
+ $this->info['object_version'] = 1;
+ return($this->ADD());
+ }
+ }else{
+ if(!$this->CheckExistence()){
+ $this->LastError="Can't edit entry, entry doesn't exists.";
+ return(false);
+ }else{
+ $this->info['db_status'] = "updated";
+ $this->info['object_version'] = $ist[0]['object_version']++;
+ return($this->EDIT());
+ }
+ }
+ }else{
+ return($this->InfoOK);
+ }
+ }
+ if($this->option == "REMOVE"){
+
+ if((!isset($this->info['login']))||(empty($this->info['login']))){
+ $this->LastError = "Require login to detect existence";
+ return(false);
+ }else{
+
+ if($this->CheckExistence()){
+ return($this->REMOVE());
+ }else{
+ $this->LastError="Can't remove non existing entry";
+ return(false);
+ }
+ }
+ }
+ }
+ }
+
+ function CheckExistence()
+ {
+ /* Check if thios entry already exists */
+ $qry = "SELECT login,name FROM person WHERE login='".$this->info['login']."';";
+ $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+ if($ist){
+ return(true);
+ }else{
+ return(false);
+ }
+ }
+
+ function checkInfos()
+ {
+ foreach($this->MUST as $name){
+ if((!isset($this->info[$name]))||(empty($this->info[$name]))){
+ $this->LastError = sprintf("Must attribute '%s' wasn't set.",$name);
+ return(false);
+ }
+ }
+
+ foreach($this->MAY as $name){
+ if((!isset($this->info[$name]))||(empty($this->info[$name]))){
+ $this->info[$name] = false;
+ }
+ }
+
+ $tmp = array(false,"",0);
+ foreach($this->validLocationTeam as $id){
+ $tmp[]= $id['company_id'];
+ }
+ if(!in_array($this->info['LocationTeamID'],$tmp)){
+ $this->LastError = "Given 'Location Team' is invalid.";
+ return(false);
+ }
+
+ $tmp = array();
+ foreach($this->validTemplateUser as $id){
+ $tmp[]= $id['company_id'];
+ }
+ if(!in_array($this->info['template_user_id'],$tmp)){
+ $this->LastError = "Given 'Template User ID' is invalid.";
+ return(false);
+ }
+
+
+ $tmp = array();
+ foreach($this->validTeams as $id){
+ $tmp[]= $id['company_id'];
+ }
+ if(is_array($this->info['TeamIDis'])){
+ foreach($this->info['TeamIDis'] as $id){
+ if(!in_array($id,$tmp)){
+ $this->LastError = sprintf("Given 'Team ID':%s is invalid.",$id);
+ return(false);
+ }
+ }
+ }
+ return(true);
+ }
+
+ function REMOVE()
+ {
+ $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
+ $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+ if((!$ist)||(!isset($ist[0]['company_id']))||($ist[0]['company_id']<=0)){
+ $this->LastError(sprintf("Can't get company id for login %s",$this->info['login']));
+ return(false);
+ }else{
+
+ $company_id = $ist[0]['company_id'];
+
+ $qry = "UPDATE person SET login='SKY".$company_id.$this->info['login']."', is_account=0, is_intra_account=0 WHERE company_id=".$company_id.";";
+ $this->ogo->Query($qry);
+ /*
+ $this->ogo->Query("DELETE FROM telephone WHERE company_id=".$company_id.";");
+ $this->ogo->Query("DELETE FROM address WHERE company_id=".$company_id.";");
+ $this->ogo->Query("DELETE FROM company_info WHERE company_id=".$company_id.";");
+ $this->ogo->Query("DELETE FROM company_value WHERE company_id=".$company_id.";");
+ $this->ogo->Query("DELETE FROM company_assignment WHERE sub_company_id=".$company_id.";");
+ $this->ogo->Query("DELETE FROM person WHERE company_id=".$company_id.";");
+ $this->ogo->Query("DELETE FROM staff WHERE company_id=".$company_id.";");
+ */
+ return(true);
+ }
+ }
+
+ function ADD()
+ {
+ /*
+ Entry settings for personm table
+ */
+ $arr = array( "company_id","object_version","owner_id","template_user_id",
+ "is_person","is_account","is_intra_account","is_extra_account",
+ "number","description","is_locked","login","name","name","firstname",
+ "salutation","degree","birthday","sex","db_status","password");
+ $this->info['company_id'] = $this->ogo->gen_id();
+ $this->info['userID'] = "OGo".$this->info['company_id'];
+ foreach($arr as $attr){
+ if($attr == "number"){
+ $add_user[$attr] = $this->info['userID'];
+ }else{
+ $add_user[$attr] = $this->info[$attr];
+ }
+ }
+ $QUERY[] = gen_syntax($add_user,"person","ADD",false);
+
+
+ /*
+ Entry for staff table
+ */
+ $arr = array("staff_id","company_id","description","login","is_team","is_account","db_status");
+ $this->info['staff_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_staff[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_staff,"staff","ADD",false);
+
+
+ /*
+ Create entries for company nfo
+ */
+ $arr = array("company_info_id","company_id","db_status");
+ $this->info['company_info_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_company_info[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_company_info,"company_info","ADD",false);
+
+
+ /*
+ Create entries for company value
+ */
+ $arr = array("db_status","value_string","attribute","company_id","company_value_id");
+ $this->info['attribute'] = "email1";
+ $this->info['company_value_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_company_value[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_company_value,"company_value","ADD",false);
+
+
+ /*
+ address entries
+ */
+ $arr = array("company_id","address_id","street","zip","country","zipcity","state","db_status","name1","type");
+ foreach(array("private","mailing","location") as $type){
+
+ $this->info['address_id'] = $this->ogo->gen_id();
+ $this->info['type'] = $type;
+ foreach($arr as $attr){
+ $add_address[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_address,"address","ADD",false);
+ }
+
+
+ /*
+ telephone entries
+ */
+ $arr = array("telephone_id","object_version","company_id","number","type","db_status");
+ foreach(array("01_tel","02_tel","03_tel_funk","05_tel_private","10_fax","fax_private") as $type){
+ $this->info['type'] = $type;
+ $this->info['telephone_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_telephone[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_telephone,"telephone","ADD",false);
+ }
+
+ /*
+ company_assignment entries (Location Team)
+ */
+ $this->info['old_company_id'] = $this->info['company_id'];
+ $this->info['sub_company_id'] = $this->info['old_company_id'];
+
+ $this->info['company_assignment_id']= $this->ogo->gen_id();
+ $this->info['company_id'] = $this->info['LocationTeamID'];
+ $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
+ foreach($arr as $attr){
+ $add_company_assignment[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
+
+
+ /*
+ company_assignment entries (Teams)
+ */
+ $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
+ foreach($this->info['TeamIDis'] as $TeamID){
+
+ $this->info['company_id'] = $TeamID;
+ $this->info['sub_company_id'] = $this->info['old_company_id'];
+ $this->info['company_assignment_id']= $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_company_assignment[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
+ }
+
+ $remove_all = false;
+ foreach($QUERY as $q ){
+ if(!$this->ogo->Query($q)){
+ $remove_all = true;
+ break;
+ }
+ }
+
+ if($remove_all== true){
+ $this->ogo->Query("DELETE FROM telephone WHERE company_id=".$this->info['company_id'].";");
+ $this->ogo->Query("DELETE FROM address WHERE company_id=".$this->info['company_id'].";");
+ $this->ogo->Query("DELETE FROM company_assignment WHERE company_id=".$this->info['company_id'].";");
+ $this->ogo->Query("DELETE FROM company_info WHERE company_id=".$this->info['company_id'].";");
+ $this->ogo->Query("DELETE FROM company_value WHERE company_id=".$this->info['company_id'].";");
+ $this->ogo->Query("DELETE FROM staff WHERE company_id=".$this->info['company_id'].";");
+ $this->ogo->Query("DELETE FROM person WHERE company_id=".$this->info['company_id'].";");
+ $this->LastError="Query failed, removed all added entries";
+ return(false);
+ }
+ return(true);
+ }
+
+
+ function EDIT()
+ {
+ $qry = "SELECT * FROM person WHERE login='".$this->info['login']."';";
+ $ist = $this->ogo->FetchAllRows($this->ogo->Query($qry));
+ /*
+ Entry settings for personm table
+ */
+ $arr = array( "company_id","object_version","owner_id",
+ "template_user_id","is_person","is_account","is_intra_account",
+ "is_extra_account","number","description","is_locked","login","name",
+ "firstname","salutation","degree","birthday","sex","db_status","password");
+ $this->info['company_id'] = $ist[0]['company_id'];
+ $this->info['userID'] = "OGo".$this->info['company_id'];
+ foreach($arr as $attr){
+ if($attr == "number"){
+ $add_user[$attr] = $this->info['userID'];
+ }else{
+ $add_user[$attr] = $this->info[$attr];
+ }
+ }
+ $QUERY[] = gen_syntax($add_user,"person","EDIT",$ist);
+
+
+ /*
+ Entry for staff table
+ */
+ $arr = array("staff_id","company_id","description","login","is_team","is_account","db_status");
+ $this->info['staff_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_staff[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_staff,"staff","EDIT",$ist);
+
+
+ /*
+ Create entries for company nfo
+ */
+ $arr = array("company_info_id","company_id","db_status");
+ $this->info['company_info_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_company_info[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_company_info,"company_info","EDIT",$ist);
+
+
+ /*
+ Create entries for company value
+ */
+ $QUERY[] = "DELETE FROM company_value WHERE company_id=".$ist[0]['company_id']." AND attribute='mail1';";
+ $arr = array("db_status","value_string","attribute","company_id","company_value_id");
+ $this->info['attribute'] = "email1";
+ $this->info['company_value_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_company_value[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_company_value,"company_value","ADD",false);
+
+
+ /*
+ address entries
+ */
+ $QUERY[] = "DELETE FROM address WHERE company_id=".$ist[0]['company_id'].";";
+ $this->info['company_id'] = $ist[0]['company_id'];
+ $arr = array("company_id","address_id","street","zip","country","zipcity","state","db_status","name1","type");
+ foreach(array("private","mailing","location") as $type){
+ $this->info['type'] = $type;
+ $this->info['address_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_address[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_address,"address","ADD",false);
+ }
+
+
+ /*
+ telephone entries
+ */
+ $QUERY[] = "DELETE FROM telephone WHERE company_id=".$ist[0]['company_id'].";";
+ $this->info['company_id'] = $ist[0]['company_id'];
+ $arr = array("telephone_id","object_version","company_id","number","type","db_status");
+ foreach(array("01_tel","02_tel","03_tel_funk","05_tel_private","10_fax","fax_private") as $type){
+ $this->info['type'] = $type;
+ $this->info['telephone_id'] = $this->ogo->gen_id();
+ foreach($arr as $attr){
+ $add_telephone[$attr] = $this->info[$attr];
+ }
+
+ $QUERY[] = gen_syntax($add_telephone,"telephone","ADD",false);
+ }
+
+
+ /*
+ company_assignment entries (Location Team)
+ */
+ $this->info['old_company_id'] = $this->info['company_id'];
+
+ /* First remove location team */
+ $QUERY[] = "DELETE FROM company_assignment WHERE (sub_company_id=".$ist[0]['company_id'].") AND
+ company_id in (SELECT company_id FROM team WHERE is_location_team=1);";
+
+ $this->info['sub_company_id'] = $ist[0]['company_id'];
+ $this->info['company_assignment_id']= $this->ogo->gen_id();
+ $this->info['company_id'] = $this->info['LocationTeamID'];
+ $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
+ foreach($arr as $attr){
+ $add_company_assignment[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
+
+
+ /*
+ company_assignment entries (Teams)
+ */
+ /* First remove location team */
+ $QUERY[] = "DELETE FROM company_assignment
+ WHERE
+ (sub_company_id=".$ist[0]['company_id'].")
+ AND
+ company_id IN
+ (SELECT company_id FROM team WHERE (is_team=1) AND company_id NOT IN
+ (SELECT company_id FROM team WHERE is_location_team=1));";
+
+ $arr = array("company_assignment_id","company_id","sub_company_id","db_status");
+
+ if(is_array($this->info['TeamIDis'])){
+ foreach($this->info['TeamIDis'] as $TeamID){
+ $this->info['company_id'] = $TeamID;
+ $this->info['sub_company_id'] = $ist[0]['company_id'];
+ $this->info['company_assignment_id']= $this->ogo->gen_id();
+ $add_company_assignment = array();
+ foreach($arr as $attr){
+ $add_company_assignment[$attr] = $this->info[$attr];
+ }
+ $QUERY[] = gen_syntax($add_company_assignment,"company_assignment","ADD",false);
+ }
+ }
+ $remove_all = false;
+
+ foreach($QUERY as $q ){
+ if(!$this->ogo-> Query($q)){
+ print $q;
+ $remove_all = true;
+ break;
+ }
+ }
+ }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-core/plugins/personal/connectivity/class_pgsql_opengw.inc b/gosa-core/plugins/personal/connectivity/class_pgsql_opengw.inc
--- /dev/null
@@ -0,0 +1,160 @@
+<?php
+
+class pgre_sql{
+
+ var $handle;
+ var $query_log;
+ var $user;
+ var $server;
+ var $db;
+ var $pwd;
+ var $is_connected = false;
+
+ function pgre_sql($user,$pwd,$server,$db)
+ {
+ $this->user = $user;
+ $this->pwd = $pwd;
+ $this->server = $server;
+ $this->db = $db;
+
+ if($this->_connect()){
+ $this->is_connected = true;
+ }else{
+ $this->is_connected = false;
+ }
+ }
+
+ function _connect()
+ {
+ error_reporting(E_ALL | E_STRICT);
+ if(is_callable("pg_connect")){
+ if(!empty($this->pwd)){
+ $this->handle = @pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user);
+ }else{
+ $this->handle = @pg_connect("dbname=".$this->db." host=".$this->server." user=".$this->user." password=".$this->pwd);
+ }
+ if(!$this->handle){
+ $this->handle = false;
+ }
+ }else{
+ $this->handle = false;
+ }
+ return($this->handle);
+ }
+
+ function Query($a_query)
+ {
+ if(is_array($a_query)){
+ foreach($a_query as $nr => $query){
+ return($this->_query($query));
+ }
+ }else{
+ return($this->_query($a_query));
+ }
+ }
+
+ function _query($query)
+ {
+ return(pg_query($this->handle,$query));
+ }
+
+ function FetchAllRows($res)
+ {
+ return(pg_fetch_all($res)) ;
+ }
+
+ function gen_id()
+ {
+ $tmp = $this->_query("select nextval('key_generator');");
+ $tmp = ($this->FetchAllRows($tmp));
+ return($tmp[0]['nextval']);
+ }
+
+
+ function GetTemplateUser(){
+ $data = array();
+ $qry = "SELECT description,name,company_id FROM company WHERE is_template_user=1;";
+ $res = $this->_query($qry);
+ $tmp = $this->FetchAllRows($res);
+ foreach($tmp as $attr){
+ $data[$attr['name']] = $attr;
+ }
+ return $data;
+ }
+ function GetLocationTeam(){
+ $data = array();
+ $qry = "SELECT description,name,company_id FROM team WHERE is_location_team=1;";
+ $res = $this->_query($qry);
+ $tmp = $this->FetchAllRows($res);
+ if(is_array($tmp)){
+ foreach($tmp as $attr){
+ $data[$attr['description']] = $attr;
+ }
+ }
+ return $data;
+ }
+ function GetTeams(){
+ $data = array();
+ $qry = "SELECT description,name,company_id FROM team
+ WHERE (is_team=1) AND company_id
+ NOT IN (SELECT company_id FROM company WHERE is_location_team=1);";
+ $res = $this->_query($qry);
+ $tmp = $this->FetchAllRows($res);
+ foreach($tmp as $attr){
+ $data[$attr['description']] = $attr;
+ }
+ return $data;
+ }
+}
+
+
+function gen_syntax($array,$tablename,$act,$ist)
+{
+ if($act == "EDIT"){
+ $str = "UPDATE ".$tablename." SET ";
+ $company_id = $ist[0]['company_id'];
+
+ foreach($array as $name => $value){
+ if((empty($value))&&(!preg_match("/^is_/i",$name))) continue;
+
+ if((empty($value))&&(preg_match("/^is_/i",$name))){
+ $value= 0;
+ }
+
+ if(!is_numeric($value)){
+ $str.= " ".$name."='".$value."', ";
+ }else{
+ $str.= " ".$name."=".$value.", ";
+ }
+ }
+ $str = preg_replace("/, $/","",$str);
+ $str .= " WHERE company_id=".$company_id.";\n";
+ return $str;
+ }
+ if($act == "ADD"){
+ $str = "INSERT into ".$tablename." (";
+ $attrs = "";
+ $values = "";
+ foreach($array as $name => $attribute){
+ if((empty($attribute))&&(!preg_match("/^is_/i",$name))) continue;
+
+ if((empty($attribute))&&(preg_match("/^is_/i",$name))){
+ $attribute= 0;
+ }
+
+ if(is_numeric($attribute)){
+ $attrs .= $name.", ";
+ $values .= $attribute.", ";
+ }else{
+ $attrs .= $name.", ";
+ $values .= "'".$attribute."', ";
+ }
+ }
+ $attrs = preg_replace("/, $/","",$attrs);
+ $values= preg_replace("/, $/","",$values);
+ $str .= $attrs." ) \nVALUES\n (".$values.");\n";
+ return $str;
+ }
+}
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>
diff --git a/gosa-core/plugins/personal/samba/class_sambaMungedDial.inc b/gosa-core/plugins/personal/samba/class_sambaMungedDial.inc
--- /dev/null
@@ -0,0 +1,609 @@
+<?php
+/*
+ This code is part of GOsa (https://gosa.gonicus.de)
+ Copyright (C) 2004 Cajus Pollmeier
+
+ This program 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.
+
+ This program 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 this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+
+/* File header is treated as constant. It cannot be defined inside the class if $PHP_VERSION < 5 */
+define ("FILEHEADER",
+ "20002000200020002000200020002000".
+ "20002000200020002000200020002000".
+ "20002000200020002000200020002000".
+ "20002000200020002000200020002000".
+ "20002000200020002000200020002000".
+ "20002000200020002000200020002000".
+ "5000");
+/* This is the old header, it is needed to automatically convert old mungedDials to new ones */
+define ("FILEHEADER_OLD",
+ "6d000800200020002000200020002000".
+ "20002000200020002000200020002000".
+ "20002000200020002000200064000100".
+ "20002000200020002000200020002000".
+ "20002000200020002000200020002000".
+ "20002000200020002000200020002000".
+ "50001000");
+
+class sambaMungedDial
+{
+ /* Terminal server variables (samba3) */
+ var $ctx= array(
+ 'CtxCfgPresent' => '551e0bb0',
+ 'CtxCfgFlags1' => '00e00010',
+ 'CtxCallback' => '',
+ 'CtxShadow' => '01000000',
+ 'CtxMaxConnectionTime' => '',
+ 'CtxMaxDisconnectionTime' => '',
+ 'CtxMaxIdleTime' => '',
+ 'CtxKeyboardLayout' => '',
+ 'CtxMinEncryptionLevel' => '00',
+ 'CtxWorkDirectory' => '',
+ 'CtxNWLogonServer' => '',
+ 'CtxWFHomeDir' => '',
+ 'CtxWFHomeDirDrive' => '',
+ 'CtxWFProfilePath' => '',
+ 'CtxInitialProgram' => '',
+ 'CtxCallbackNumber' => '');
+
+ /* attribute list for save action */
+ var $ctxattributes= array("CtxCfgPresent", "CtxCfgFlags1", "CtxCallback",
+ "CtxShadow", "CtxMaxConnectionTime", "CtxMaxDisconnectionTime",
+ "CtxMaxIdleTime", "CtxKeyboardLayout", "CtxMinEncryptionLevel",
+ "CtxWorkDirectory", "CtxNWLogonServer", "CtxWFHomeDir",
+ "CtxWFHomeDirDrive", "CtxWFProfilePath", "CtxInitialProgram",
+ "CtxCallbackNumber");
+
+ /* These parameters are treated as strings and get a trailing zero */
+ var $stringParams= array( "CtxWorkDirectory", "CtxNWLogonServer",
+ "CtxWFHomeDir", "CtxWFHomeDirDrive",
+ "CtxWFProfilePath", "CtxInitialProgram", "CtxCallbackNumber");
+
+ /* These parameters are treated as time values and get converted */
+ var $timeParams= array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime");
+
+ var $old_behavior= false;
+
+ function strhex($string)
+ {
+ $hex="";
+
+ for ($i=0; $i<strlen($string); $i++) {
+ $hex.= dechex(ord($string[$i]));
+ }
+
+ return ($hex);
+ }
+
+ function hexstr($hex)
+ {
+ $string="";
+
+ for ($i=0; $i<strlen($hex)-1; $i+=2) {
+ $string.= chr(hexdec($hex[$i].$hex[$i+1]));
+ }
+
+ return ($string);
+ }
+
+ function endian($src)
+ {
+ return (substr($src, 2, 2).substr($src, 0, 2));
+ }
+
+ function genTime ($minutes)
+ {
+ $usec= (int) ($minutes * 60 * 1000);
+ $src= sprintf('%04x%04x', $usec & 0x0FFFF, ($usec & 0x0FFFF0000) >> 16);
+ return (sambaMungedDial::endian(substr($src, 0, 4)).sambaMungedDial::endian(substr($src, 4, 4)));
+ }
+
+ function readTime ($time)
+ {
+ $lo= substr($time, 0, 4);
+ $hi= substr($time, 4, 4);
+
+ $usecs= (hexdec(substr($lo, 2, 2)) * 256 + hexdec(substr($lo, 0, 2))) +
+ (hexdec(substr($hi, 2 ,2)) * 256 + hexdec(substr($hi, 0, 2))) * 256 * 256;
+
+ return ((int)($usecs / (60 * 1000)));
+ }
+
+ function to8bit($string)
+ {
+ $result= "";
+
+ /* Strip zeros */
+ for ($i= 0; $i<strlen($string); $i++){
+ if ($string[$i] != chr(0)){
+ $result.= $string[$i];
+ }
+ }
+
+ return ($result);
+ }
+
+ function is_samba_path($path)
+ {
+ if ($path == ""){
+ return (TRUE);
+ }
+
+ if (!preg_match('/^[a-z0-9%\\\\_.:+-\\\\$]+$/i', $path)){
+ return (FALSE);
+ }
+
+ return preg_match ("/\\\\.+$/", $path);
+ }
+
+ /* Encode full MungedDial-String */
+ function encode_munged ($params)
+ {
+ /* Walk through the parameters and convert them */
+ $result= sambaMungedDial::hexstr(FILEHEADER);
+
+ // CHANGED: We need to insert the number of attributes right after FILEHEADER.
+ $counter= 0;
+ $result_tmp= "";
+ foreach ($params as $paramName => $paramValue) {
+ /* String parameter? */
+ if (in_array($paramName, $this->stringParams)){
+ $isString= TRUE;
+ $paramValue= sambaMungedDial::strhex($paramValue.chr(0).chr(0));
+ } else {
+ $isString= FALSE;
+ }
+
+ /* Time parameter? */
+ if (in_array($paramName, $this->timeParams)){
+ $paramValue= sambaMungedDial::genTime($paramValue);
+ }
+
+ $result_tmp.= sambaMungedDial::munge($paramName, $paramValue, $isString);
+ $counter++;
+ }
+
+ // First add the number of attributes
+ $result.= sambaMungedDial::hexstr(sprintf("%02x00", $counter));
+
+ // Then the usual stuff
+ $result.= $result_tmp;
+
+ return ($result);
+ }
+
+ /* Setup parameter given by paramName to MungedDial-Format */
+ function munge($paramName, $paramValue, $isString)
+ {
+ $result= "";
+
+ /* Encode paramName to UTF-16 */
+ if (function_exists("recode")){
+ $utfName= recode("ISO8859-15..UTF-16", $paramName);
+ } else {
+ $utfName= iconv("ISO8859-15", "UTF-16BE", $paramName);
+ }
+
+ /* Set parameter length, high and low byte */
+ $paramLen= strlen($utfName);
+ $result.= chr($paramLen & 0x0FF);
+ $result.= chr(($paramLen & 0x0FF00) >> 8);
+
+ /* String parameters have additional trailing bytes */
+ $valueLen= strlen($paramValue);
+ $result.= chr($valueLen & 0x0FF);
+ $result.= chr(($valueLen & 0x0FF00) >> 8);
+
+ /* Length fields have a trailing '01' appended by the UTF-16 converted name */
+ $result.= chr(1);
+ $result.= $utfName;
+
+ /* Parameter is padded with '00' */
+ $result.= chr(0);
+ $result.= $paramValue;
+
+ /* Append a trailing '00' to string parameters */
+ if ($isString && (strlen($paramValue) & 1)){
+ $result.= chr(0);
+ }
+
+ return ($result);
+ }
+
+ /* Takes a base64-encoded MungedDial-String and returns an array of included parameters and values */
+ function decode_munged($munge)
+ {
+ $result= array();
+
+ /*
+ * Remove base64 encoding and skip FILEHEADER.
+ * The '4' is added, because the FILEHEADER has been stripped by 4 chars.
+ * This is the number of attributes following - we don't need this at read time, only when writing.
+ */
+ if(substr(base64_decode($munge),0,2)=="6d") {
+ $this->old_behavior=true;
+ }
+
+ $ctxField="";
+ if($this->old_behavior==true) {
+ $ctxField= substr(base64_decode($munge), (strlen(FILEHEADER_OLD)) / 2);
+ } else {
+ $ctxField= substr(base64_decode($munge), (strlen(FILEHEADER)+4) / 2);
+ }
+
+ /* Decode parameters */
+ while ($ctxField!=""){
+
+ /* Read value lengths */
+ $ctxParmNameLength= ord($ctxField[0]) + 16 * ord($ctxField[1]);
+ $ctxParmLength= ord($ctxField[2]) + 16 * ord($ctxField[3]);
+
+ /* Reposition ctxField on start of parameter name, read parameter name */
+ $ctxField= substr($ctxField, 6);
+ $ctxParmName= sambaMungedDial::to8bit(substr($ctxField, 0, $ctxParmNameLength));
+
+ /* Reposition ctxField on start of parameter */
+ $ctxField= substr($ctxField, $ctxParmNameLength);
+ $ctxParm= substr($ctxField, 0, $ctxParmLength);
+
+ /* If string parameter, convert */
+ if (in_array($ctxParmName, $this->stringParams)){
+ $ctxParm= sambaMungedDial::hexstr($ctxParm);
+ }
+ /* If time parameter, convert */
+ if (in_array($ctxParmName, $this->timeParams)){
+ $ctxParm= sambaMungedDial::readTime($ctxParm);
+ }
+
+ /* Assign in result array */
+ $result[$ctxParmName]= trim($ctxParm);
+
+ /* Reposition ctxField on end of parameter and continue */
+ $ctxField= substr($ctxField, $ctxParmLength);
+ }
+
+ return ($result);
+ }
+
+ /* function takes a base64-encoded sambaMungedDial */
+ function load ($mungedDial)
+ {
+ $this->ctx= $this->decode_munged($mungedDial);
+ }
+
+ /* Returns ready-to-run mungedDialString to be filled into ldap */
+ function getMunged ()
+ {
+ // Do extra check for valid timeParams (they must be set to 0 if disabled)
+ foreach($this->timeParams as $value) {
+ if(!isset($this->ctx[$value])) {
+ $this->ctx[$value]= 0;
+ }
+ }
+ $result= base64_encode($this->encode_munged($this->ctx));
+
+ return $result;
+ }
+
+ /* Returns array of flags, which can be set on-demand with activated java-script */
+ function getOnDemandFlags ()
+ {
+ $result= array();
+ if (session::get("js")){
+ foreach ($this->timeParams as $value) {
+ if (!isset($this->ctx[$value]) || (isset($this->ctx[$value]) && $this->ctx[$value] == 0)) {
+ $result[$value."Mode"]= "disabled";
+ } else {
+ $result[$value."Mode"]= "";
+ }
+ }
+
+ if (substr($this->ctx['CtxCfgFlags1'], 6, 1) == "1") {
+ $result['CtxInitialProgramMode'] = "disabled";
+ } else {
+ $result['CtxInitialProgramMode'] = "";
+ }
+ }else{
+ foreach ($this->timeParams as $value) {
+ $result[$value."Mode"]= "";
+ }
+
+ $result['CtxInitialProgramMode'] = "";
+
+ }
+
+ return $result;
+ }
+
+ /*Gets Terminal-Server-Login value: enabled/disabled */
+ function getTsLogin ()
+ {
+ $flags= ord(substr($this->ctx['CtxCfgFlags1'], 5, 1));
+
+ if ($flags & 1) {
+ $result= false;
+ } else {
+ $result= true;
+ }
+
+ return $result;
+ }
+
+ /* Sets Terminal-Server-Login value: enabled/disabled */
+ function setTsLogin ($checked)
+ {
+ $flag= substr($this->ctx['CtxCfgFlags1'], 5, 1);
+
+ if ($checked) {
+ $flag|= 1;
+ } else {
+ $flag&= 0xFE;
+ }
+
+ $this->ctx['CtxCfgFlags1'][5]= sprintf('%1x', $flag);
+ }
+
+ /* gets Broken-Connection value: disconnect/reset */
+ function getBrokenConn ()
+ {
+ $flags= ord(substr($this->ctx['CtxCfgFlags1'], 5, 1));
+ if ($flags & 4) {
+ $result= "1";
+ } else {
+ $result= "0";
+ }
+
+ return $result;
+ }
+
+ /* sets Broken-Connection value: disconnect/reset */
+ function setBrokenConn ($checked)
+ {
+ $flag= substr($this->ctx['CtxCfgFlags1'], 5, 1);
+
+ if ($checked) {
+ $flag|= 4;
+ } else {
+ $flag&= 0xFB;
+ }
+
+ $this->ctx['CtxCfgFlags1'][5]= sprintf('%1x', $flag);
+ }
+
+ /* gets Reconnection value: from any client/from previous client only */
+ function getReConn ()
+ {
+ $flags= ord(substr($this->ctx['CtxCfgFlags1'], 5, 1));
+ if ($flags & 2) {
+ $result= "1";
+ } else {
+ $result= "0";
+ }
+
+ return $result;
+ }
+
+ /* sets Reconnection value: from any client/from previous client only */
+ function setReConn ($checked)
+ {
+ $flag= substr($this->ctx['CtxCfgFlags1'], 5, 1);
+
+ if ($checked) {
+ $flag|= 2;
+ } else {
+ $flag&= 0xFD;
+ }
+
+ $this->ctx['CtxCfgFlags1'][5]= sprintf('%1x', $flag);
+ }
+
+ /* gets Inherit-config-from-client value: enabled/disabled */
+ function getInheritMode ()
+ {
+ if (substr($this->ctx['CtxCfgFlags1'], 6, 1) == "1") {
+ $result= true;
+ } else {
+ $result= false;
+ }
+
+ return $result;
+ }
+
+ /* sets Inherit-config-from-client value: enabled/disabled */
+ function setInheritMode ($checked)
+ {
+ if ($checked) {
+ $this->ctx['CtxCfgFlags1'][6]= "1";
+ } else {
+ $this->ctx['CtxCfgFlags1'][6]= "0";
+ }
+ }
+
+ /* gets shadow value (enum): 0-4
+ 0: disabled
+ 1: input on, notify on
+ 2: input on, notify off
+ 3: input off, notify on
+ 4: input off, notify off
+ */
+ function getShadow ()
+ {
+ if($this->old_behavior==true) {
+ $result= substr($this->ctx['CtxCfgFlags1'], 1, 1);
+ } else {
+ $result= substr($this->ctx['CtxShadow'], 1, 1);
+ }
+ return $result;
+ }
+
+ /* sets shadow value */
+ function setShadow ($checked, $value)
+ {
+ if ($checked) {
+ if($this->old_behavior==true) {
+ // We need to reset the old setting
+ $this->ctx['CtxCfgFlags1'][1]= sprintf('%1X', $value);
+ }
+ $this->ctx['CtxShadow'][1]= sprintf('%1x', $value);
+ }
+ }
+
+ /* gets connect-client-drive-at-logon value: enabled/disabled */
+ function getConnectClientDrives ()
+ {
+ $connections= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
+ if ($connections & 8) {
+ $result= true;
+ } else {
+ $result= false;
+ }
+
+ return $result;
+ }
+
+ /* sets connect-client-drive-at-logon value: enabled/disabled */
+ function setConnectClientDrives ($checked)
+ {
+ $flag= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
+ if ($checked) {
+ $flag|= 8;
+ } else {
+ $flag&= 0xF7;
+ }
+
+ $this->ctx['CtxCfgFlags1'][2]= sprintf('%1x', $flag);
+ }
+
+ /* gets connect-client-printers-at-logon value: enabled/disabled */
+ function getConnectClientPrinters ()
+ {
+ $connections= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
+ if ($connections & 4) {
+ $result= true;
+ } else {
+ $result= false;
+ }
+
+ return $result;
+ }
+
+ /* sets connect-client-printers-at-logon value: enabled/disabled */
+ function setConnectClientPrinters ($checked)
+ {
+ $flag= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
+
+ if ($checked) {
+ $flag|= 4;
+ } else {
+ $flag&= 0xFB;
+ }
+
+ $this->ctx['CtxCfgFlags1'][2]= sprintf('%1x', $flag);
+ }
+
+ /* gets set-client-printer-to-default value: enabled/disabled */
+ function getDefaultPrinter ()
+ {
+ $connections= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
+ if ($connections & 2) {
+ $result= true;
+ } else {
+ $result= false;
+ }
+
+ return $result;
+ }
+
+ /* sets set-client-printer-to-default value: enabled/disabled */
+ function setDefaultPrinter ($checked)
+ {
+ $flag= hexdec(substr($this->ctx['CtxCfgFlags1'], 2, 1));
+
+ if ($checked) {
+ $flag|= 2;
+ } else {
+ $flag&= 0xFD;
+ }
+
+ $this->ctx['CtxCfgFlags1'][2]= sprintf('%1x', $flag);
+ }
+
+ /* SMARTY: gets the checkbox state of "Connection" */
+ function getCtxMaxConnectionTimeF ()
+ {
+ // Connection Time is 0 if disabled
+ if (isset($this->ctx['CtxMaxConnectionTime']) && ($this->ctx['CtxMaxConnectionTime'] != 0)) {
+ $result= true;
+ } else {
+ $result= false;
+ }
+
+ return $result;
+ }
+
+ /* SMARTY: sets the checkbox "Connection" to unchecked */
+ function setCtxMaxConnectionTimeF ($checked)
+ {
+ if ($checked) {
+ unset ($this->ctx['CtxMaxConnectionTime']);
+ }
+ }
+
+ /* SMARTY: gets the checkbox state of "Disconnection" */
+ function getCtxMaxDisconnectionTimeF ()
+ {
+ // Connection Time is 0 if disabled
+ if (isset($this->ctx['CtxMaxDisconnectionTime']) && ($this->ctx['CtxMaxDisconnectionTime'] != 0)) {
+ $result= true;
+ } else {
+ $result= false;
+ }
+
+ return $result;
+ }
+
+ /* SMARTY: sets the checkbox "Disconnection" to unchecked */
+ function setCtxMaxDisconnectionTimeF ($checked)
+ {
+ if ($checked) {
+ unset ($this->ctx['CtxMaxDisconnectionTime']);
+ }
+ }
+
+ /* SMARTY: gets the checkbox state of "Idle" */
+ function getCtxMaxIdleTimeF ()
+ {
+ // Connection Time is 0 if disabled
+ if (isset($this->ctx['CtxMaxIdleTime']) && ($this->ctx['CtxMaxIdleTime'] != 0)) {
+ $result= true;
+ } else {
+ $result= false;
+ }
+
+ return $result;
+ }
+
+ /* SMARTY: sets the checkbox "Idle" to unchecked */
+ function setCtxMaxIdleTimeF ($checked)
+ {
+ if ($checked) {
+ unset ($this->ctx['CtxMaxIdleTime']);
+ }
+ }
+}
+
+// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
+?>