attributedef.class.inc.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314
  1. <?php
  2. require_once('MyHelpers.class.inc.php');
  3. require_once('ormdocument.class.inc.php');
  4. /**
  5. * MissingColumnException - sent if an attribute is being created but the column is missing in the row
  6. *
  7. * @package iTopORM
  8. */
  9. class MissingColumnException extends Exception
  10. {}
  11. /**
  12. * add some description here...
  13. *
  14. * @package iTopORM
  15. */
  16. define('EXTKEY_RELATIVE', 1);
  17. /**
  18. * add some description here...
  19. *
  20. * @package iTopORM
  21. */
  22. define('EXTKEY_ABSOLUTE', 2);
  23. /**
  24. * Propagation of the deletion through an external key - ask the user to delete the referencing object
  25. *
  26. * @package iTopORM
  27. */
  28. define('DEL_MANUAL', 1);
  29. /**
  30. * Propagation of the deletion through an external key - ask the user to delete the referencing object
  31. *
  32. * @package iTopORM
  33. */
  34. define('DEL_AUTO', 2);
  35. /**
  36. * Attribute definition API, implemented in and many flavours (Int, String, Enum, etc.)
  37. *
  38. * @package iTopORM
  39. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  40. * @author Denis Flaven <denisflave@free.fr>
  41. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  42. * @link www.itop.com
  43. * @since 1.0
  44. * @version 1.1.1.1 $
  45. */
  46. abstract class AttributeDefinition
  47. {
  48. abstract public function GetType();
  49. abstract public function GetTypeDesc();
  50. abstract public function GetEditClass();
  51. protected $m_sCode;
  52. private $m_aParams = array();
  53. private $m_sHostClass = array();
  54. protected function Get($sParamName) {return $this->m_aParams[$sParamName];}
  55. public function __construct($sCode, $aParams)
  56. {
  57. $this->m_sCode = $sCode;
  58. $this->m_aParams = $aParams;
  59. $this->ConsistencyCheck();
  60. }
  61. public function OverloadParams($aParams)
  62. {
  63. foreach ($aParams as $sParam => $value)
  64. {
  65. if (!array_key_exists($sParam, $this->m_aParams))
  66. {
  67. throw new CoreException("Unknown attribute definition parameter '$sParam', please select a value in {".implode(", ", $this->m_aParams)."}");
  68. }
  69. else
  70. {
  71. $this->m_aParams[$sParam] = $value;
  72. }
  73. }
  74. }
  75. public function SetHostClass($sHostClass)
  76. {
  77. $this->m_sHostClass = $sHostClass;
  78. }
  79. public function GetHostClass()
  80. {
  81. return $this->m_sHostClass;
  82. }
  83. // Note: I could factorize this code with the parameter management made for the AttributeDef class
  84. // to be overloaded
  85. static protected function ListExpectedParams()
  86. {
  87. return array("label", "description");
  88. }
  89. private function ConsistencyCheck()
  90. {
  91. // Check that any mandatory param has been specified
  92. //
  93. $aExpectedParams = $this->ListExpectedParams();
  94. foreach($aExpectedParams as $sParamName)
  95. {
  96. if (!array_key_exists($sParamName, $this->m_aParams))
  97. {
  98. $aBacktrace = debug_backtrace();
  99. $sTargetClass = $aBacktrace[2]["class"];
  100. $sCodeInfo = $aBacktrace[1]["file"]." - ".$aBacktrace[1]["line"];
  101. throw new Exception("ERROR missing parameter '$sParamName' in ".get_class($this)." declaration for class $sTargetClass ($sCodeInfo)");
  102. }
  103. }
  104. }
  105. // table, key field, name field
  106. public function ListDBJoins()
  107. {
  108. return "";
  109. // e.g: return array("Site", "infrid", "name");
  110. }
  111. public function IsDirectField() {return false;}
  112. public function IsScalar() {return false;}
  113. public function IsLinkSet() {return false;}
  114. public function IsExternalKey($iType = EXTKEY_RELATIVE) {return false;}
  115. public function IsExternalField() {return false;}
  116. public function IsWritable() {return false;}
  117. public function IsNullAllowed() {return true;}
  118. public function GetCode() {return $this->m_sCode;}
  119. public function GetLabel() {return $this->Get("label");}
  120. public function GetDescription() {return $this->Get("description");}
  121. public function GetValuesDef() {return null;}
  122. public function GetPrerequisiteAttributes() {return array();}
  123. //public function IsSearchableStd() {return $this->Get("search_std");}
  124. //public function IsSearchableGlobal() {return $this->Get("search_global");}
  125. //public function IsMandatory() {return $this->Get("is_mandatory");}
  126. //public function GetMinVal() {return $this->Get("min");}
  127. //public function GetMaxVal() {return $this->Get("max");}
  128. //public function GetSize() {return $this->Get("size");}
  129. //public function GetCheckRegExp() {return $this->Get("regexp");}
  130. //public function GetCheckFunc() {return $this->Get("checkfunc");}
  131. public function MakeRealValue($proposedValue) {return $proposedValue;} // force an allowed value (type conversion and possibly forces a value as mySQL would do upon writing!)
  132. public function GetSQLExpressions() {return array();} // returns suffix/expression pairs (1 in most of the cases), for READING (Select)
  133. public function FromSQLToValue($aCols, $sPrefix = '') {return null;} // returns a value out of suffix/value pairs, for SELECT result interpretation
  134. public function GetSQLColumns() {return array();} // returns column/spec pairs (1 in most of the cases), for STRUCTURING (DB creation)
  135. public function GetSQLValues($value) {return array();} // returns column/value pairs (1 in most of the cases), for WRITING (Insert, Update)
  136. public function GetJSCheckFunc()
  137. {
  138. $sRegExp = $this->Get("regexp");
  139. if (empty($sRegExp)) return 'return true;';
  140. return "return regexp('$sRegExp', myvalue);";
  141. }
  142. public function CheckValue($value)
  143. {
  144. $sRegExp = $this->Get("regexp");
  145. if (empty($sRegExp)) return true;
  146. return preg_match(preg_escape($this->Get("regexp")), $value);
  147. }
  148. public function MakeValue()
  149. {
  150. $sComputeFunc = $this->Get("compute_func");
  151. if (empty($sComputeFunc)) return null;
  152. return call_user_func($sComputeFunc);
  153. }
  154. abstract public function GetDefaultValue();
  155. //
  156. // To be overloaded in subclasses
  157. //
  158. abstract public function GetBasicFilterOperators(); // returns an array of "opCode"=>"description"
  159. abstract public function GetBasicFilterLooseOperator(); // returns an "opCode"
  160. //abstract protected GetBasicFilterHTMLInput();
  161. abstract public function GetBasicFilterSQLExpr($sOpCode, $value);
  162. public function GetAsHTML($sValue)
  163. {
  164. return Str::pure2html((string)$sValue);
  165. }
  166. public function GetAsXML($sValue)
  167. {
  168. return Str::pure2xml((string)$sValue);
  169. }
  170. public function GetAsCSV($sValue, $sSeparator = ';', $sSepEscape = ',')
  171. {
  172. return str_replace($sSeparator, $sSepEscape, (string)$sValue);
  173. }
  174. public function GetAllowedValues($aArgs = array(), $sBeginsWith = '')
  175. {
  176. $oValSetDef = $this->GetValuesDef();
  177. if (!$oValSetDef) return null;
  178. return $oValSetDef->GetValues($aArgs, $sBeginsWith);
  179. }
  180. }
  181. /**
  182. * Set of objects directly linked to an object, and being part of its definition
  183. *
  184. * @package iTopORM
  185. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  186. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  187. * @link www.itop.com
  188. * @since 1.0
  189. * @version $itopversion$
  190. */
  191. class AttributeLinkedSet extends AttributeDefinition
  192. {
  193. static protected function ListExpectedParams()
  194. {
  195. return array_merge(parent::ListExpectedParams(), array("allowed_values", "depends_on", "linked_class", "ext_key_to_me", "count_min", "count_max"));
  196. }
  197. public function GetType() {return "Array of objects";}
  198. public function GetTypeDesc() {return "Any kind of objects [subclass] of the same class";}
  199. public function GetEditClass() {return "List";}
  200. public function IsWritable() {return true;}
  201. public function IsLinkSet() {return true;}
  202. public function GetValuesDef() {return $this->Get("allowed_values");}
  203. public function GetPrerequisiteAttributes() {return $this->Get("depends_on");}
  204. public function GetDefaultValue() {return DBObjectSet::FromScratch($this->Get('linked_class'));}
  205. public function GetLinkedClass() {return $this->Get('linked_class');}
  206. public function GetExtKeyToMe() {return $this->Get('ext_key_to_me');}
  207. public function GetBasicFilterOperators() {return array();}
  208. public function GetBasicFilterLooseOperator() {return '';}
  209. public function GetBasicFilterSQLExpr($sOpCode, $value) {return '';}
  210. public function GetAsHTML($sValue)
  211. {
  212. return "ERROR: LIST OF OBJECTS";
  213. }
  214. public function GetAsXML($sValue)
  215. {
  216. return "ERROR: LIST OF OBJECTS";
  217. }
  218. public function GetAsCSV($sValue, $sSeparator = ';', $sSepEscape = ',')
  219. {
  220. return "ERROR: LIST OF OBJECTS";
  221. }
  222. }
  223. /**
  224. * Set of objects linked to an object (n-n), and being part of its definition
  225. *
  226. * @package iTopORM
  227. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  228. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  229. * @link www.itop.com
  230. * @since 1.0
  231. * @version $itopversion$
  232. */
  233. class AttributeLinkedSetIndirect extends AttributeLinkedSet
  234. {
  235. static protected function ListExpectedParams()
  236. {
  237. return array_merge(parent::ListExpectedParams(), array("ext_key_to_remote"));
  238. }
  239. public function GetExtKeyToRemote() { return $this->Get('ext_key_to_remote'); }
  240. }
  241. /**
  242. * Abstract class implementing default filters for a DB column
  243. *
  244. * @package iTopORM
  245. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  246. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  247. * @link www.itop.com
  248. * @since 1.0
  249. * @version $itopversion$
  250. */
  251. class AttributeDBFieldVoid extends AttributeDefinition
  252. {
  253. static protected function ListExpectedParams()
  254. {
  255. return array_merge(parent::ListExpectedParams(), array("allowed_values", "depends_on", "sql"));
  256. }
  257. // To be overriden, used in GetSQLColumns
  258. protected function GetSQLCol() {return "VARCHAR(255)";}
  259. public function GetType() {return "Void";}
  260. public function GetTypeDesc() {return "Any kind of value, from the DB";}
  261. public function GetEditClass() {return "String";}
  262. public function GetValuesDef() {return $this->Get("allowed_values");}
  263. public function GetPrerequisiteAttributes() {return $this->Get("depends_on");}
  264. public function IsDirectField() {return true;}
  265. public function IsScalar() {return true;}
  266. public function IsWritable() {return true;}
  267. public function GetSQLExpr() {return $this->Get("sql");}
  268. public function GetDefaultValue() {return "";}
  269. public function IsNullAllowed() {return false;}
  270. protected function ScalarToSQL($value) {return $value;} // format value as a valuable SQL literal (quoted outside)
  271. protected function SQLToScalar($value) {return $value;} // take the result of a fetch... and make it a PHP variable
  272. public function GetSQLExpressions()
  273. {
  274. $aColumns = array();
  275. // Note: to optimize things, the existence of the attribute is determine by the existence of one column with an empty suffix
  276. $aColumns[''] = $this->Get("sql");
  277. return $aColumns;
  278. }
  279. public function FromSQLToValue($aCols, $sPrefix = '')
  280. {
  281. $value = $this->MakeRealValue($aCols[$sPrefix.'']);
  282. return $value;
  283. }
  284. public function GetSQLValues($value)
  285. {
  286. $aValues = array();
  287. $aValues[$this->Get("sql")] = $this->ScalarToSQL($value);
  288. return $aValues;
  289. }
  290. public function GetSQLColumns()
  291. {
  292. $aColumns = array();
  293. $aColumns[$this->Get("sql")] = $this->GetSQLCol();
  294. return $aColumns;
  295. }
  296. public function GetBasicFilterOperators()
  297. {
  298. return array("="=>"equals", "!="=>"differs from");
  299. }
  300. public function GetBasicFilterLooseOperator()
  301. {
  302. return "=";
  303. }
  304. public function GetBasicFilterSQLExpr($sOpCode, $value)
  305. {
  306. $sQValue = CMDBSource::Quote($value);
  307. switch ($sOpCode)
  308. {
  309. case '!=':
  310. return $this->GetSQLExpr()." != $sQValue";
  311. break;
  312. case '=':
  313. default:
  314. return $this->GetSQLExpr()." = $sQValue";
  315. }
  316. }
  317. }
  318. /**
  319. * Base class for all kind of DB attributes, with the exception of external keys
  320. *
  321. * @package iTopORM
  322. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  323. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  324. * @link www.itop.com
  325. * @since 1.0
  326. * @version $itopversion$
  327. */
  328. class AttributeDBField extends AttributeDBFieldVoid
  329. {
  330. static protected function ListExpectedParams()
  331. {
  332. return array_merge(parent::ListExpectedParams(), array("default_value", "is_null_allowed"));
  333. }
  334. public function GetDefaultValue() {return $this->Get("default_value");}
  335. public function IsNullAllowed() {return strtolower($this->Get("is_null_allowed"));}
  336. }
  337. /**
  338. * Map an integer column to an attribute
  339. *
  340. * @package iTopORM
  341. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  342. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  343. * @link www.itop.com
  344. * @since 1.0
  345. * @version $itopversion$
  346. */
  347. class AttributeInteger extends AttributeDBField
  348. {
  349. static protected function ListExpectedParams()
  350. {
  351. return parent::ListExpectedParams();
  352. //return array_merge(parent::ListExpectedParams(), array());
  353. }
  354. public function GetType() {return "Integer";}
  355. public function GetTypeDesc() {return "Numeric value (could be negative)";}
  356. public function GetEditClass() {return "String";}
  357. protected function GetSQLCol() {return "INT";}
  358. public function GetBasicFilterOperators()
  359. {
  360. return array(
  361. "!="=>"differs from",
  362. "="=>"equals",
  363. ">"=>"greater (strict) than",
  364. ">="=>"greater than",
  365. "<"=>"less (strict) than",
  366. "<="=>"less than",
  367. "in"=>"in"
  368. );
  369. }
  370. public function GetBasicFilterLooseOperator()
  371. {
  372. // Unless we implement an "equals approximately..." or "same order of magnitude"
  373. return "=";
  374. }
  375. public function GetBasicFilterSQLExpr($sOpCode, $value)
  376. {
  377. $sQValue = CMDBSource::Quote($value);
  378. switch ($sOpCode)
  379. {
  380. case '!=':
  381. return $this->GetSQLExpr()." != $sQValue";
  382. break;
  383. case '>':
  384. return $this->GetSQLExpr()." > $sQValue";
  385. break;
  386. case '>=':
  387. return $this->GetSQLExpr()." >= $sQValue";
  388. break;
  389. case '<':
  390. return $this->GetSQLExpr()." < $sQValue";
  391. break;
  392. case '<=':
  393. return $this->GetSQLExpr()." <= $sQValue";
  394. break;
  395. case 'in':
  396. if (!is_array($value)) throw new CoreException("Expected an array for argument value (sOpCode='$sOpCode')");
  397. return $this->GetSQLExpr()." IN ('".implode("', '", $value)."')";
  398. break;
  399. case '=':
  400. default:
  401. return $this->GetSQLExpr()." = \"$value\"";
  402. }
  403. }
  404. public function MakeRealValue($proposedValue)
  405. {
  406. //return intval($proposedValue); could work as well
  407. return (int)$proposedValue;
  408. }
  409. public function ScalarToSQL($value)
  410. {
  411. assert(is_numeric($value));
  412. return $value; // supposed to be an int
  413. }
  414. public function SQLToScalar($value)
  415. {
  416. // Use cast (int) or intval() ?
  417. return (int)$value;
  418. }
  419. }
  420. /**
  421. * Map a varchar column (size < ?) to an attribute
  422. *
  423. * @package iTopORM
  424. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  425. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  426. * @link www.itop.com
  427. * @since 1.0
  428. * @version $itopversion$
  429. */
  430. class AttributeString extends AttributeDBField
  431. {
  432. static protected function ListExpectedParams()
  433. {
  434. return parent::ListExpectedParams();
  435. //return array_merge(parent::ListExpectedParams(), array());
  436. }
  437. public function GetType() {return "String";}
  438. public function GetTypeDesc() {return "Alphanumeric string";}
  439. public function GetEditClass() {return "String";}
  440. protected function GetSQLCol() {return "VARCHAR(255)";}
  441. public function GetBasicFilterOperators()
  442. {
  443. return array(
  444. "="=>"equals",
  445. "!="=>"differs from",
  446. "Like"=>"equals (no case)",
  447. "NotLike"=>"differs from (no case)",
  448. "Contains"=>"contains",
  449. "Begins with"=>"begins with",
  450. "Finishes with"=>"finishes with"
  451. );
  452. }
  453. public function GetBasicFilterLooseOperator()
  454. {
  455. return "Contains";
  456. }
  457. public function GetBasicFilterSQLExpr($sOpCode, $value)
  458. {
  459. $sQValue = CMDBSource::Quote($value);
  460. switch ($sOpCode)
  461. {
  462. case '=':
  463. case '!=':
  464. return $this->GetSQLExpr()." $sOpCode $sQValue";
  465. case 'Begins with':
  466. return $this->GetSQLExpr()." LIKE ".CMDBSource::Quote("$value%");
  467. case 'Finishes with':
  468. return $this->GetSQLExpr()." LIKE ".CMDBSource::Quote("%$value");
  469. case 'Contains':
  470. return $this->GetSQLExpr()." LIKE ".CMDBSource::Quote("%$value%");
  471. case 'NotLike':
  472. return $this->GetSQLExpr()." NOT LIKE $sQValue";
  473. case 'Like':
  474. default:
  475. return $this->GetSQLExpr()." LIKE $sQValue";
  476. }
  477. }
  478. public function MakeRealValue($proposedValue)
  479. {
  480. return (string)$proposedValue;
  481. // if (!settype($proposedValue, "string"))
  482. // {
  483. // throw new CoreException("Failed to change the type of '$proposedValue' to a string");
  484. // }
  485. }
  486. public function ScalarToSQL($value)
  487. {
  488. if (!is_string($value) && !is_null($value))
  489. {
  490. throw new CoreWarning('Expected the attribute value to be a string', array('found_type' => gettype($value), 'value' => $value, 'class' => $this->GetCode(), 'attribute' => $this->GetHostClass()));
  491. }
  492. return $value;
  493. }
  494. public function SQLToScalar($value)
  495. {
  496. return $value;
  497. }
  498. }
  499. /**
  500. * Map a varchar column (size < ?) to an attribute that must never be shown to the user
  501. *
  502. * @package iTopORM
  503. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  504. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  505. * @link www.itop.com
  506. * @since 1.0
  507. * @version $itopversion$
  508. */
  509. class AttributePassword extends AttributeString
  510. {
  511. static protected function ListExpectedParams()
  512. {
  513. return parent::ListExpectedParams();
  514. //return array_merge(parent::ListExpectedParams(), array());
  515. }
  516. public function GetEditClass() {return "Password";}
  517. protected function GetSQLCol() {return "VARCHAR(64)";}
  518. }
  519. /**
  520. * Map a text column (size > ?) to an attribute
  521. *
  522. * @package iTopORM
  523. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  524. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  525. * @link www.itop.com
  526. * @since 1.0
  527. * @version $itopversion$
  528. */
  529. class AttributeText extends AttributeString
  530. {
  531. public function GetType() {return "Text";}
  532. public function GetTypeDesc() {return "Multiline character string";}
  533. public function GetEditClass() {return "Text";}
  534. protected function GetSQLCol() {return "TEXT";}
  535. public function GetAsHTML($sValue)
  536. {
  537. return str_replace("\n", "<br>\n", parent::GetAsHTML($sValue));
  538. }
  539. public function GetAsXML($value)
  540. {
  541. return Str::pure2xml($value);
  542. }
  543. public function GetAsCSV($value, $sSeparator = ';', $sSepEscape = ',')
  544. {
  545. return str_replace("\n", "[newline]", parent::GetAsCSV($sValue, $sSeparator, $sSepEscape));
  546. }
  547. }
  548. /**
  549. * Specialization of a string: email
  550. *
  551. * @package iTopORM
  552. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  553. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  554. * @link www.itop.com
  555. * @since 1.0
  556. * @version $itopversion$
  557. */
  558. class AttributeEmailAddress extends AttributeString
  559. {
  560. public function GetTypeDesc() {return "Email address(es)";}
  561. }
  562. /**
  563. * Specialization of a string: OQL expression
  564. *
  565. * @package iTopORM
  566. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  567. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  568. * @link www.itop.com
  569. * @since 1.0
  570. * @version $itopversion$
  571. */
  572. class AttributeOQL extends AttributeString
  573. {
  574. public function GetTypeDesc() {return "OQL expression";}
  575. }
  576. /**
  577. * Specialization of a string: template
  578. *
  579. * @package iTopORM
  580. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  581. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  582. * @link www.itop.com
  583. * @since 1.0
  584. * @version $itopversion$
  585. */
  586. class AttributeTemplateString extends AttributeString
  587. {
  588. public function GetTypeDesc() {return "Template string";}
  589. }
  590. /**
  591. * Specialization of a text: template
  592. *
  593. * @package iTopORM
  594. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  595. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  596. * @link www.itop.com
  597. * @since 1.0
  598. * @version $itopversion$
  599. */
  600. class AttributeTemplateText extends AttributeText
  601. {
  602. public function GetTypeDesc() {return "Multiline template string";}
  603. }
  604. /**
  605. * Map a enum column to an attribute
  606. *
  607. * @package iTopORM
  608. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  609. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  610. * @link www.itop.com
  611. * @since 1.0
  612. * @version $itopversion$
  613. */
  614. class AttributeEnum extends AttributeString
  615. {
  616. static protected function ListExpectedParams()
  617. {
  618. return parent::ListExpectedParams();
  619. //return array_merge(parent::ListExpectedParams(), array());
  620. }
  621. public function GetType() {return "Enum";}
  622. public function GetTypeDesc() {return "List of predefined alphanumeric strings";}
  623. public function GetEditClass() {return "String";}
  624. protected function GetSQLCol()
  625. {
  626. $oValDef = $this->GetValuesDef();
  627. if ($oValDef)
  628. {
  629. $aValues = CMDBSource::Quote($oValDef->GetValues(array(), ""), true);
  630. }
  631. else
  632. {
  633. $aValues = array();
  634. }
  635. if (count($aValues) > 0)
  636. {
  637. return "ENUM(".implode(", ", $aValues).")";
  638. }
  639. else
  640. {
  641. return "VARCHAR(255)"; // ENUM() is not an allowed syntax!
  642. }
  643. }
  644. public function GetBasicFilterOperators()
  645. {
  646. return parent::GetBasicFilterOperators();
  647. }
  648. public function GetBasicFilterLooseOperator()
  649. {
  650. return parent::GetBasicFilterLooseOperator();
  651. }
  652. public function GetBasicFilterSQLExpr($sOpCode, $value)
  653. {
  654. return parent::GetBasicFilterSQLExpr($sOpCode, $value);
  655. }
  656. }
  657. /**
  658. * Map a date+time column to an attribute
  659. *
  660. * @package iTopORM
  661. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  662. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  663. * @link www.itop.com
  664. * @since 1.0
  665. * @version $itopversion$
  666. */
  667. class AttributeDate extends AttributeDBField
  668. {
  669. const MYDATEFORMAT = "Y-m-d H:i:s";
  670. //const MYDATETIMEZONE = "UTC";
  671. const MYDATETIMEZONE = "Europe/Paris";
  672. static protected $const_TIMEZONE = null; // set once for all upon object construct
  673. static public function InitStatics()
  674. {
  675. // Init static constant once for all (remove when PHP allows real static const)
  676. self::$const_TIMEZONE = new DateTimeZone(self::MYDATETIMEZONE);
  677. // #@# Init default timezone -> do not get a notice... to be improved !!!
  678. date_default_timezone_set(self::MYDATETIMEZONE);
  679. }
  680. static protected function ListExpectedParams()
  681. {
  682. return parent::ListExpectedParams();
  683. //return array_merge(parent::ListExpectedParams(), array());
  684. }
  685. public function GetType() {return "Date";}
  686. public function GetTypeDesc() {return "Date and time";}
  687. public function GetEditClass() {return "Date";}
  688. protected function GetSQLCol() {return "TIMESTAMP";}
  689. // #@# THIS HAS TO REVISED
  690. // Having null not allowed was interpreted by mySQL
  691. // which was creating the field with the flag 'ON UPDATE CURRENT_TIMESTAMP'
  692. // Then, on each update of the record, the field was modified.
  693. // We will have to specify the default value if we want to restore this option
  694. // In fact, we could also have more verbs dedicated to the DB:
  695. // GetDBDefaultValue()... or GetDBFieldCreationStatement()....
  696. public function IsNullAllowed() {return true;}
  697. public function GetDefaultValue()
  698. {
  699. $default = parent::GetDefaultValue();
  700. if (!parent::IsNullAllowed())
  701. {
  702. if (empty($default))
  703. {
  704. $default = date("Y-m-d H:i");
  705. }
  706. }
  707. return $default;
  708. }
  709. // END OF THE WORKAROUND
  710. ///////////////////////////////////////////////////////////////
  711. public function GetBasicFilterOperators()
  712. {
  713. return array(
  714. "="=>"equals",
  715. "!="=>"differs from",
  716. "<"=>"before",
  717. "<="=>"before",
  718. ">"=>"after (strictly)",
  719. ">="=>"after",
  720. "SameDay"=>"same day (strip time)",
  721. "SameMonth"=>"same year/month",
  722. "SameYear"=>"same year",
  723. "Today"=>"today",
  724. ">|"=>"after today + N days",
  725. "<|"=>"before today + N days",
  726. "=|"=>"equals today + N days",
  727. );
  728. }
  729. public function GetBasicFilterLooseOperator()
  730. {
  731. // Unless we implement a "same xxx, depending on given precision" !
  732. return "=";
  733. }
  734. public function GetBasicFilterSQLExpr($sOpCode, $value)
  735. {
  736. $sQValue = CMDBSource::Quote($value);
  737. switch ($sOpCode)
  738. {
  739. case '=':
  740. case '!=':
  741. case '<':
  742. case '<=':
  743. case '>':
  744. case '>=':
  745. return $this->GetSQLExpr()." $sOpCode $sQValue";
  746. case 'SameDay':
  747. return "DATE(".$this->GetSQLExpr().") = DATE($sQValue)";
  748. case 'SameMonth':
  749. return "DATE_FORMAT(".$this->GetSQLExpr().", '%Y-%m') = DATE_FORMAT($sQValue, '%Y-%m')";
  750. case 'SameYear':
  751. return "MONTH(".$this->GetSQLExpr().") = MONTH($sQValue)";
  752. case 'Today':
  753. return "DATE(".$this->GetSQLExpr().") = CURRENT_DATE()";
  754. case '>|':
  755. return "DATE(".$this->GetSQLExpr().") > DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
  756. case '<|':
  757. return "DATE(".$this->GetSQLExpr().") < DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
  758. case '=|':
  759. return "DATE(".$this->GetSQLExpr().") = DATE_ADD(CURRENT_DATE(), INTERVAL $sQValue DAY)";
  760. default:
  761. return $this->GetSQLExpr()." = $sQValue";
  762. }
  763. }
  764. public function MakeRealValue($proposedValue)
  765. {
  766. if (!is_numeric($proposedValue))
  767. {
  768. return $proposedValue;
  769. }
  770. else
  771. {
  772. return date("Y-m-d H:i:s", $proposedValue);
  773. }
  774. throw new CoreException("Invalid type for a date (found ".gettype($proposedValue)." and accepting string/int/DateTime)");
  775. return null;
  776. }
  777. public function ScalarToSQL($value)
  778. {
  779. if (empty($value))
  780. {
  781. // Make a valid date for MySQL. TO DO: support NULL as a literal value for fields that can be null.
  782. return '0000-00-00 00:00:00';
  783. }
  784. return $value;
  785. }
  786. public function SQLToScalar($value)
  787. {
  788. return $value;
  789. }
  790. public function GetAsHTML($value)
  791. {
  792. return Str::pure2html($value);
  793. }
  794. public function GetAsXML($value)
  795. {
  796. return Str::pure2xml($value);
  797. }
  798. public function GetAsCSV($value, $sSeparator = ';', $sSepEscape = ',')
  799. {
  800. return str_replace($sSeparator, $sSepEscape, $value);
  801. }
  802. }
  803. // Init static constant once for all (remove when PHP allows real static const)
  804. AttributeDate::InitStatics();
  805. /**
  806. * Map a foreign key to an attribute
  807. * AttributeExternalKey and AttributeExternalField may be an external key
  808. * the difference is that AttributeExternalKey corresponds to a column into the defined table
  809. * where an AttributeExternalField corresponds to a column into another table (class)
  810. *
  811. * @package iTopORM
  812. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  813. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  814. * @link www.itop.com
  815. * @since 1.0
  816. * @version $itopversion$
  817. */
  818. class AttributeExternalKey extends AttributeDBFieldVoid
  819. {
  820. static protected function ListExpectedParams()
  821. {
  822. return array_merge(parent::ListExpectedParams(), array("targetclass", "is_null_allowed", "on_target_delete"));
  823. }
  824. public function GetType() {return "Extkey";}
  825. public function GetTypeDesc() {return "Link to another object";}
  826. public function GetEditClass() {return "ExtKey";}
  827. protected function GetSQLCol() {return "INT";}
  828. public function IsExternalKey($iType = EXTKEY_RELATIVE) {return true;}
  829. public function GetTargetClass($iType = EXTKEY_RELATIVE) {return $this->Get("targetclass");}
  830. public function GetKeyAttDef($iType = EXTKEY_RELATIVE){return $this;}
  831. public function GetKeyAttCode() {return $this->GetCode();}
  832. public function GetDefaultValue() {return 0;}
  833. public function IsNullAllowed() {return $this->Get("is_null_allowed");}
  834. public function GetBasicFilterOperators()
  835. {
  836. return parent::GetBasicFilterOperators();
  837. }
  838. public function GetBasicFilterLooseOperator()
  839. {
  840. return parent::GetBasicFilterLooseOperator();
  841. }
  842. public function GetBasicFilterSQLExpr($sOpCode, $value)
  843. {
  844. return parent::GetBasicFilterSQLExpr($sOpCode, $value);
  845. }
  846. // overloaded here so that an ext key always have the answer to
  847. // "what are your possible values?"
  848. public function GetValuesDef()
  849. {
  850. $oValSetDef = $this->Get("allowed_values");
  851. if (!$oValSetDef)
  852. {
  853. // Let's propose every existing value
  854. $oValSetDef = new ValueSetObjects($this->GetTargetClass());
  855. }
  856. return $oValSetDef;
  857. }
  858. public function GetAllowedValues($aArgs = array(), $sBeginsWith = '')
  859. {
  860. try
  861. {
  862. return parent::GetAllowedValues($aArgs, $sBeginsWith);
  863. }
  864. catch (MissingQueryArgument $e)
  865. {
  866. // Some required arguments could not be found, enlarge to any existing value
  867. $oValSetDef = new ValueSetObjects($this->GetTargetClass());
  868. return $oValSetDef->GetValues($aArgs, $sBeginsWith);
  869. }
  870. }
  871. public function GetDeletionPropagationOption()
  872. {
  873. return $this->Get("on_target_delete");
  874. }
  875. }
  876. /**
  877. * An attribute which corresponds to an external key (direct or indirect)
  878. *
  879. * @package iTopORM
  880. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  881. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  882. * @link www.itop.com
  883. * @since 1.0
  884. * @version $itopversion$
  885. */
  886. class AttributeExternalField extends AttributeDefinition
  887. {
  888. static protected function ListExpectedParams()
  889. {
  890. return array_merge(parent::ListExpectedParams(), array("extkey_attcode", "target_attcode"));
  891. }
  892. public function GetType() {return "ExtkeyField";}
  893. public function GetTypeDesc() {return "Field of an object pointed to by the current object";}
  894. public function GetEditClass() {return "ExtField";}
  895. protected function GetSQLCol()
  896. {
  897. // throw new CoreException("external attribute: does it make any sense to request its type ?");
  898. $oExtAttDef = $this->GetExtAttDef();
  899. return $oExtAttDef->GetSQLCol();
  900. }
  901. public function IsExternalKey($iType = EXTKEY_RELATIVE)
  902. {
  903. switch($iType)
  904. {
  905. case EXTKEY_ABSOLUTE:
  906. // see further
  907. $oRemoteAtt = $this->GetExtAttDef();
  908. return $oRemoteAtt->IsExternalKey($iType);
  909. case EXTKEY_RELATIVE:
  910. return false;
  911. default:
  912. throw new CoreException("Unexpected value for argument iType: '$iType'");
  913. }
  914. }
  915. public function GetTargetClass($iType = EXTKEY_RELATIVE)
  916. {
  917. return $this->GetKeyAttDef($iType)->GetTargetClass();
  918. }
  919. public function IsExternalField() {return true;}
  920. public function GetKeyAttCode() {return $this->Get("extkey_attcode");}
  921. public function GetExtAttCode() {return $this->Get("target_attcode");}
  922. public function GetKeyAttDef($iType = EXTKEY_RELATIVE)
  923. {
  924. switch($iType)
  925. {
  926. case EXTKEY_ABSOLUTE:
  927. // see further
  928. $oRemoteAtt = $this->GetExtAttDef();
  929. if ($oRemoteAtt->IsExternalField())
  930. {
  931. return $oRemoteAtt->GetKeyAttDef(EXTKEY_ABSOLUTE);
  932. }
  933. else if ($oRemoteAtt->IsExternalKey())
  934. {
  935. return $oRemoteAtt;
  936. }
  937. return $this->GetKeyAttDef(EXTKEY_RELATIVE); // which corresponds to the code hereafter !
  938. case EXTKEY_RELATIVE:
  939. return MetaModel::GetAttributeDef($this->GetHostClass(), $this->Get("extkey_attcode"));
  940. default:
  941. throw new CoreException("Unexpected value for argument iType: '$iType'");
  942. }
  943. }
  944. public function GetExtAttDef()
  945. {
  946. $oKeyAttDef = $this->GetKeyAttDef();
  947. $oExtAttDef = MetaModel::GetAttributeDef($oKeyAttDef->Get("targetclass"), $this->Get("target_attcode"));
  948. return $oExtAttDef;
  949. }
  950. public function GetSQLExpr()
  951. {
  952. $oExtAttDef = $this->GetExtAttDef();
  953. return $oExtAttDef->GetSQLExpr();
  954. }
  955. public function GetDefaultValue()
  956. {
  957. $oExtAttDef = $this->GetExtAttDef();
  958. return $oExtAttDef->GetDefaultValue();
  959. }
  960. public function IsNullAllowed()
  961. {
  962. $oExtAttDef = $this->GetExtAttDef();
  963. return $oExtAttDef->IsNullAllowed();
  964. }
  965. public function GetBasicFilterOperators()
  966. {
  967. $oExtAttDef = $this->GetExtAttDef();
  968. return $oExtAttDef->GetBasicFilterOperators();
  969. }
  970. public function GetBasicFilterLooseOperator()
  971. {
  972. $oExtAttDef = $this->GetExtAttDef();
  973. return $oExtAttDef->GetBasicFilterLooseOperator();
  974. }
  975. public function GetBasicFilterSQLExpr($sOpCode, $value)
  976. {
  977. $oExtAttDef = $this->GetExtAttDef();
  978. return $oExtAttDef->GetBasicFilterSQLExpr($sOpCode, $value);
  979. }
  980. public function MakeRealValue($proposedValue)
  981. {
  982. $oExtAttDef = $this->GetExtAttDef();
  983. return $oExtAttDef->MakeRealValue($proposedValue);
  984. }
  985. public function ScalarToSQL($value)
  986. {
  987. // This one could be used in case of filtering only
  988. $oExtAttDef = $this->GetExtAttDef();
  989. return $oExtAttDef->ScalarToSQL($value);
  990. }
  991. public function SQLToScalar($value)
  992. {
  993. $oExtAttDef = $this->GetExtAttDef();
  994. return $oExtAttDef->SQLToScalar($value);
  995. }
  996. // Do not overload GetSQLExpression here because this is handled in the joins
  997. //public function GetSQLExpressions() {return array();}
  998. // Here, we get the data...
  999. public function FromSQLToValue($aCols, $sPrefix = '')
  1000. {
  1001. $oExtAttDef = $this->GetExtAttDef();
  1002. return $oExtAttDef->FromSQLToValue($aCols, $sPrefix);
  1003. }
  1004. public function GetAsHTML($value)
  1005. {
  1006. $oExtAttDef = $this->GetExtAttDef();
  1007. return $oExtAttDef->GetAsHTML($value);
  1008. }
  1009. public function GetAsXML($value)
  1010. {
  1011. $oExtAttDef = $this->GetExtAttDef();
  1012. return $oExtAttDef->GetAsXML($value);
  1013. }
  1014. public function GetAsCSV($value, $sSeparator = ';', $sSepEscape = ',')
  1015. {
  1016. $oExtAttDef = $this->GetExtAttDef();
  1017. return $oExtAttDef->GetAsCSV($value);
  1018. }
  1019. }
  1020. /**
  1021. * Map a varchar column to an URL (formats the ouput in HMTL)
  1022. *
  1023. * @package iTopORM
  1024. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  1025. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  1026. * @link www.itop.com
  1027. * @since 1.0
  1028. * @version $itopversion$
  1029. */
  1030. class AttributeURL extends AttributeString
  1031. {
  1032. static protected function ListExpectedParams()
  1033. {
  1034. //return parent::ListExpectedParams();
  1035. return array_merge(parent::ListExpectedParams(), array("target", "label"));
  1036. }
  1037. public function GetType() {return "Url";}
  1038. public function GetTypeDesc() {return "Absolute or relative URL as a text string";}
  1039. public function GetEditClass() {return "String";}
  1040. public function GetAsHTML($sValue)
  1041. {
  1042. $sTarget = $this->Get("target");
  1043. if (empty($sTarget)) $sTarget = "_blank";
  1044. $sLabel = Str::pure2html($sValue);
  1045. if (strlen($sLabel) > 40)
  1046. {
  1047. // Truncate the length to about 40 characters, by removing the middle
  1048. $sLabel = substr($sLabel, 0, 25).'...'.substr($sLabel, -15);
  1049. }
  1050. return "<a target=\"$sTarget\" href=\"$sValue\">$sLabel</a>";
  1051. }
  1052. }
  1053. /**
  1054. * Data column, consisting in TWO columns in the DB
  1055. *
  1056. * @package iTopORM
  1057. * @author Romain Quetiez <romainquetiez@yahoo.fr>
  1058. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  1059. * @link www.itop.com
  1060. * @since 1.0
  1061. * @version $itopversion$
  1062. */
  1063. class AttributeBlob extends AttributeDefinition
  1064. {
  1065. static protected function ListExpectedParams()
  1066. {
  1067. return array_merge(parent::ListExpectedParams(), array("depends_on"));
  1068. }
  1069. public function GetType() {return "Blob";}
  1070. public function GetTypeDesc() {return "Document";}
  1071. public function GetEditClass() {return "Document";}
  1072. public function IsDirectField() {return true;}
  1073. public function IsScalar() {return true;}
  1074. public function IsWritable() {return true;}
  1075. public function GetDefaultValue() {return "";}
  1076. public function IsNullAllowed() {return false;}
  1077. // Facilitate things: allow the user to Set the value from a string
  1078. public function MakeRealValue($proposedValue)
  1079. {
  1080. if (!is_object($proposedValue))
  1081. {
  1082. return new ormDocument($proposedValue, 'text/plain');
  1083. }
  1084. return $proposedValue;
  1085. }
  1086. public function GetSQLExpressions()
  1087. {
  1088. $aColumns = array();
  1089. // Note: to optimize things, the existence of the attribute is determined by the existence of one column with an empty suffix
  1090. $aColumns[''] = $this->GetCode().'_mimetype';
  1091. $aColumns['_data'] = $this->GetCode().'_data';
  1092. $aColumns['_filename'] = $this->GetCode().'_filename';
  1093. return $aColumns;
  1094. }
  1095. public function FromSQLToValue($aCols, $sPrefix = '')
  1096. {
  1097. if (!isset($aCols[$sPrefix]))
  1098. {
  1099. $sAvailable = implode(', ', array_keys($aCols));
  1100. throw new MissingColumnException("Missing column '$sPrefix' from {$sAvailable}");
  1101. }
  1102. $sMimeType = $aCols[$sPrefix];
  1103. if (!isset($aCols[$sPrefix.'_data']))
  1104. {
  1105. $sAvailable = implode(', ', array_keys($aCols));
  1106. throw new MissingColumnException("Missing column '".$sPrefix."_data' from {$sAvailable}");
  1107. }
  1108. $data = $aCols[$sPrefix.'_data'];
  1109. if (!isset($aCols[$sPrefix.'_filename']))
  1110. {
  1111. $sAvailable = implode(', ', array_keys($aCols));
  1112. throw new MissingColumnException("Missing column '".$sPrefix."_filename' from {$sAvailable}");
  1113. }
  1114. $sFileName = $aCols[$sPrefix.'_filename'];
  1115. $value = new ormDocument($data, $sMimeType, $sFileName);
  1116. return $value;
  1117. }
  1118. public function GetSQLValues($value)
  1119. {
  1120. // #@# Optimization: do not load blobs anytime
  1121. // As per mySQL doc, selecting blob columns will prevent mySQL from
  1122. // using memory in case a temporary table has to be created
  1123. // (temporary tables created on disk)
  1124. // We will have to remove the blobs from the list of attributes when doing the select
  1125. // then the use of Get() should finalize the load
  1126. $aValues = array();
  1127. $aValues[$this->GetCode().'_data'] = $value->GetData();
  1128. $aValues[$this->GetCode().'_mimetype'] = $value->GetMimeType();
  1129. $aValues[$this->GetCode().'_filename'] = $value->GetFileName();
  1130. return $aValues;
  1131. }
  1132. public function GetSQLColumns()
  1133. {
  1134. $aColumns = array();
  1135. $aColumns[$this->GetCode().'_data'] = 'LONGBLOB'; // 2^32 (4 Gb)
  1136. $aColumns[$this->GetCode().'_mimetype'] = 'VARCHAR(255)';
  1137. $aColumns[$this->GetCode().'_filename'] = 'VARCHAR(255)';
  1138. return $aColumns;
  1139. }
  1140. public function GetBasicFilterOperators()
  1141. {
  1142. return array();
  1143. }
  1144. public function GetBasicFilterLooseOperator()
  1145. {
  1146. return '=';
  1147. }
  1148. public function GetBasicFilterSQLExpr($sOpCode, $value)
  1149. {
  1150. return 'true';
  1151. }
  1152. public function GetAsHTML($value)
  1153. {
  1154. if (is_object($value))
  1155. {
  1156. return $value->GetAsHTML();
  1157. }
  1158. }
  1159. public function GetAsCSV($sValue, $sSeparator = ';', $sSepEscape = ',')
  1160. {
  1161. return ''; // Not exportable in CSV !
  1162. }
  1163. public function GetAsXML($value)
  1164. {
  1165. return ''; // Not exportable in XML, or as CDATA + some subtags ??
  1166. }
  1167. }
  1168. ?>