| 1 |
<?php
|
| 2 |
/**
|
| 3 |
* Class helpDeskTimeInfo
|
| 4 |
* @package helpdesk
|
| 5 |
* Copyright OSI 2005. Licensed under GPL version 2.
|
| 6 |
* $Id$
|
| 7 |
*/
|
| 8 |
// echo "<p>Start of " . __FILE__ . "</p>" ;
|
| 9 |
$_timeinfo_saved_er = error_reporting (E_ALL | E_STRICT) ;
|
| 10 |
|
| 11 |
/**
|
| 12 |
* import ancillary functions
|
| 13 |
*/
|
| 14 |
require_once("misc.php") ;
|
| 15 |
|
| 16 |
/**
|
| 17 |
* import HD core
|
| 18 |
*/
|
| 19 |
require_once("core.php");
|
| 20 |
|
| 21 |
/**
|
| 22 |
* VIEW: Time value, drupal style
|
| 23 |
* @subpackage helpdesk_time
|
| 24 |
*/
|
| 25 |
class helpdeskTimeValue
|
| 26 |
{
|
| 27 |
/**
|
| 28 |
* POSIX timestamp
|
| 29 |
* @var integer
|
| 30 |
*/
|
| 31 |
public $ts ;
|
| 32 |
/**
|
| 33 |
* is it to be displayed in views/forms
|
| 34 |
* @var boolean
|
| 35 |
*/
|
| 36 |
public $isShown ;
|
| 37 |
/**
|
| 38 |
* is it to be enabled in forms
|
| 39 |
* @var boolean
|
| 40 |
*/
|
| 41 |
public $isEnabled;
|
| 42 |
/**
|
| 43 |
* HTML render size in forms
|
| 44 |
* @var integer
|
| 45 |
*/
|
| 46 |
public $size;
|
| 47 |
/**
|
| 48 |
* HTML max length in forms
|
| 49 |
* @var integer
|
| 50 |
*/
|
| 51 |
public $maxLength;
|
| 52 |
/**
|
| 53 |
* format code for drupal's format_date
|
| 54 |
* @var string
|
| 55 |
* @see http://drupaldocs.org/api/4.6/function/format_date API
|
| 56 |
*/
|
| 57 |
public $format;
|
| 58 |
/**
|
| 59 |
* HTML name attribute in forms
|
| 60 |
* @var string
|
| 61 |
*/
|
| 62 |
public $name ;
|
| 63 |
|
| 64 |
/**
|
| 65 |
* Init default value: beware, they are mutually dependent
|
| 66 |
* @return void
|
| 67 |
*/
|
| 68 |
function __construct()
|
| 69 |
{
|
| 70 |
$this->size = 16 ;
|
| 71 |
$this->maxLength = 16 ;
|
| 72 |
$this->format = 'small' ; // do not localize
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
| 76 |
* formats a time value for the use of a form
|
| 77 |
* 0 or empty displayed as empty
|
| 78 |
* @return string HTML for form field
|
| 79 |
*/
|
| 80 |
function form_field ()
|
| 81 |
{
|
| 82 |
$disabled = array ('disabled' => 'disabled') ; // Do not localize !
|
| 83 |
if (isset($this->ts) && ($this->ts > 0))
|
| 84 |
$ret = format_date($this->ts, $this->format) ;
|
| 85 |
else
|
| 86 |
$ret = '' ;
|
| 87 |
|
| 88 |
$ret = form_textfield(
|
| 89 |
'',
|
| 90 |
$this->name,
|
| 91 |
$ret,
|
| 92 |
$this->size,
|
| 93 |
$this->maxLength,
|
| 94 |
NULL,
|
| 95 |
($this->isEnabled ? NULL : $disabled),
|
| 96 |
TRUE) ;
|
| 97 |
|
| 98 |
return $ret;
|
| 99 |
}
|
| 100 |
}
|
| 101 |
|
| 102 |
//===========================================================================================
|
| 103 |
|
| 104 |
/**
|
| 105 |
* TimeInfo class implementing S.A.M.E. properties
|
| 106 |
* @subpackage helpdesk_time
|
| 107 |
*/
|
| 108 |
class helpdeskTimeInfo extends helpdeskObject
|
| 109 |
{
|
| 110 |
/**
|
| 111 |
* Indexed array of S.A.M.E. helpdeskTimeValues
|
| 112 |
* @var array
|
| 113 |
*/
|
| 114 |
public $values ;
|
| 115 |
/**
|
| 116 |
* Title when TI is displayed in a form
|
| 117 |
* @var string plain text
|
| 118 |
*/
|
| 119 |
public $title ;
|
| 120 |
/**
|
| 121 |
* description for forms
|
| 122 |
* @var string
|
| 123 |
*/
|
| 124 |
public $description;
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Enumerate S.A.M.E. properties.
|
| 128 |
* Defining the array as a global doesn't work (why?) so
|
| 129 |
* I return this from a method. It belongs in the class anyway
|
| 130 |
* @return array
|
| 131 |
*/
|
| 132 |
function enumKeys ()
|
| 133 |
{
|
| 134 |
return array('S', 'A', 'M', 'E') ;
|
| 135 |
}
|
| 136 |
|
| 137 |
/**
|
| 138 |
* Enumerate the titles of the S.A.M.E. properties
|
| 139 |
* @return array
|
| 140 |
*/
|
| 141 |
function enumKeyTitles ()
|
| 142 |
{
|
| 143 |
return array('S' => t('Start'), 'A' => t('Access'), 'M' => t('Modify'), 'E' => t('End'));
|
| 144 |
}
|
| 145 |
|
| 146 |
/**
|
| 147 |
* constructor MUST run to initialize SAME array
|
| 148 |
* @return void
|
| 149 |
*/
|
| 150 |
function __construct()
|
| 151 |
{
|
| 152 |
$this->values = array();
|
| 153 |
foreach ($this->enumKeys() as $key)
|
| 154 |
$this->values[$key] = new helpdeskTimeValue();
|
| 155 |
}
|
| 156 |
|
| 157 |
/**
|
| 158 |
* initialize fields in existing timeinfo from param array
|
| 159 |
* @param array $ar S.A.M.E. timestamps. Cheating: it should be an object
|
| 160 |
* @param boolean $fromDB
|
| 161 |
* @return void
|
| 162 |
*/
|
| 163 |
function init($ar, $fromDB)
|
| 164 |
{
|
| 165 |
foreach ($this->enumKeys() as $key)
|
| 166 |
{
|
| 167 |
$this->values[$key]->ts = $ar[ $key ];
|
| 168 |
$this->values[$key]->isShown = $ar[ "show$key"];
|
| 169 |
$this->values[$key]->isEnabled = $ar["enabled$key"];
|
| 170 |
}
|
| 171 |
}
|
| 172 |
|
| 173 |
/**
|
| 174 |
* Builds the form representation of a helpdesk_timeinfo
|
| 175 |
* @param boolean $enabledS If function show the S column, is it enabled ?
|
| 176 |
* @return string HTML form code
|
| 177 |
*/
|
| 178 |
function form()
|
| 179 |
{
|
| 180 |
$ret = '' ;
|
| 181 |
|
| 182 |
$header = array () ;
|
| 183 |
$row = array () ;
|
| 184 |
foreach ($this->enumKeyTitles() as $key => $value)
|
| 185 |
{
|
| 186 |
if ($this->values[$key]->isShown)
|
| 187 |
{
|
| 188 |
array_push ($header, $value) ;
|
| 189 |
array_push ($row, $this->values[$key]->form_field()) ;
|
| 190 |
}
|
| 191 |
}
|
| 192 |
|
| 193 |
$items = theme_table ($header, array ($row));
|
| 194 |
|
| 195 |
$ret .= form_group
|
| 196 |
(
|
| 197 |
$this->title,
|
| 198 |
$items,
|
| 199 |
$this->description,
|
| 200 |
NULL) ;
|
| 201 |
unset ($items) ;
|
| 202 |
return $ret ;
|
| 203 |
}
|
| 204 |
|
| 205 |
/**
|
| 206 |
* display a timeinfo, typically for hook_view
|
| 207 |
* @return string HTML
|
| 208 |
*/
|
| 209 |
function view()
|
| 210 |
{
|
| 211 |
$header = array();
|
| 212 |
foreach ($this->enumKeys() as $key)
|
| 213 |
{
|
| 214 |
if ($this->values[$key]->isShown)
|
| 215 |
{ $header[] = $this->values[$key] ; }
|
| 216 |
}
|
| 217 |
$output = theme_table($header, NULL);
|
| 218 |
return $output;
|
| 219 |
}
|
| 220 |
}
|
| 221 |
|
| 222 |
error_reporting($_timeinfo_saved_er) ;
|
| 223 |
unset ($_timeinfo_saved_er) ;
|
| 224 |
|
| 225 |
// echo "<p>End of " . __FILE__ . "</p>" ;
|
| 226 |
?>
|