PageRenderTime 57ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/common/lib/Form/Class.TextField.inc.php

https://github.com/xrg/a2billing
PHP | 201 lines | 156 code | 35 blank | 10 comment | 14 complexity | 3be7d3ac45e81d772d54dadeac5a7637 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. require_once("Class.BaseField.inc.php");
  3. class TextField extends BaseField{
  4. public $def_value;
  5. function TextField($fldtitle, $fldname, $flddescr=null, $fldwidth = null){
  6. $this->fieldname = $fldname;
  7. $this->fieldtitle = $fldtitle;
  8. $this->listWidth = $fldwidth;
  9. $this->editDescr = $flddescr;
  10. }
  11. public function DispList(array &$qrow,&$form){
  12. echo htmlspecialchars($qrow[$this->fieldname]);
  13. }
  14. public function renderSpecial(array &$qrow,&$form,$rmode, &$robj){
  15. return $qrow[$this->fieldname];
  16. }
  17. public function DispAddEdit($val,&$form){
  18. ?><input type="text" name="<?= $form->prefix.$this->fieldname ?>" value="<?=
  19. htmlspecialchars($val);?>" />
  20. <div class="descr"><?= $this->editDescr?></div>
  21. <?php
  22. }
  23. public function getDefault() {
  24. return $this->def_value;
  25. }
  26. };
  27. /** Text field, which will hyperlink to the Edit page */
  28. class TextFieldEH extends TextField{
  29. public $message = null;
  30. public function DispList(array &$qrow,&$form){
  31. if ($this->message)
  32. $msg=$this->message;
  33. else
  34. $msg=str_params(_("Edit this %1"),array($form->model_name_s),1);
  35. echo '<a href="'. $form->askeditURL($qrow) . '" title="'.$msg .'">';
  36. echo htmlspecialchars($qrow[$this->fieldname]);
  37. echo '</a>';
  38. }
  39. };
  40. /** Text field, which will hyperlink to the Details page */
  41. class TextFieldDH extends TextField{
  42. public $message = null;
  43. public function DispList(array &$qrow,&$form){
  44. if ($this->message)
  45. $msg=$this->message;
  46. else
  47. $msg=str_params(_("Details of this %1"),array($form->model_name_s),1);
  48. if ($form->getAction()!='list')
  49. return parent::DispList($qrow,$form);
  50. $pkparams= $form->getPKparams($qrow,true);
  51. $pkparams[$form->prefix.'action']='details';
  52. $url= $_SERVER['PHP_SELF'].$form->gen_AllGetParams($pkparams);
  53. echo '<a href="' .$url. '" title="'.$msg .'">';
  54. parent::DispList($qrow,$form);
  55. echo '</a>';
  56. }
  57. };
  58. /** Another variation: one that doesn't add-edit, but is displayed as a static
  59. label */
  60. class TextRoFieldEH extends TextFieldEH{
  61. public function DispAddEdit($val,&$form){
  62. echo htmlspecialchars($val);
  63. }
  64. public function buildInsert(&$ins_arr,&$form){
  65. }
  66. public function buildUpdate(&$ins_arr,&$form){
  67. }
  68. };
  69. class TextAreaField extends TextField{
  70. public $listLimit;
  71. function TextAreaField($fldtitle, $fldname, $llimit=30, $flddescr=null, $fldwidth = null){
  72. $this->fieldname = $fldname;
  73. $this->fieldtitle = $fldtitle;
  74. $this->listWidth = $fldwidth;
  75. $this->listLimit = $llimit;
  76. $this->editDescr = $flddescr;
  77. }
  78. public function DispList(array &$qrow,&$form){
  79. if (strlen($qrow[$this->fieldname])>$this->listLimit)
  80. echo substr(htmlspecialchars($qrow[$this->fieldname]), 0, $this->listLimit). '...';
  81. else
  82. echo htmlspecialchars($qrow[$this->fieldname]);
  83. }
  84. public function DispAddEdit($val,&$form){
  85. ?><textarea name="<?= $form->prefix.$this->fieldname ?>" rows=5 cols=40><?=
  86. htmlspecialchars($val);?></textarea>
  87. <div class="descr"><?= $this->editDescr?></div>
  88. <?php
  89. }
  90. };
  91. /** Text field, allows for null values (if empty */
  92. class TextFieldN extends TextField{
  93. public function buildValue($val,&$form){
  94. if (empty($val))
  95. return null;
  96. else
  97. return $val;
  98. }
  99. };
  100. /** A password, viewable.
  101. This field is merely an edit field, with a random default. The password
  102. will be visible in the web ui, since it needs to be communicated to the
  103. user (so far). It is not listable, though.
  104. */
  105. class PasswdField extends TextField{
  106. public $pwtype;
  107. public $pwlen = 8;
  108. function PasswdField($fldtitle, $fldname,$fldtype, $flddescr=null, $fldwidth = null){
  109. $this->does_list=false;
  110. $this->fieldname = $fldname;
  111. $this->fieldtitle = $fldtitle;
  112. $this->pwtype=$fldtype;
  113. $this->listWidth = $fldwidth;
  114. $this->editDescr = $flddescr;
  115. }
  116. public function getDefault() {
  117. $str = "";
  118. switch ($this->pwtype){
  119. case 'num':
  120. for ($i=0;$i<$this->pwlen;$i++)
  121. $str .= mt_rand(0,9);
  122. break;
  123. case 'alnum':
  124. default:
  125. $enc = sha1(mt_rand().mt_rand().mt_rand());
  126. $str = substr($enc, 1, $this->pwlen);
  127. }
  128. return $str;
  129. }
  130. public function DispList(array &$qrow,&$form){
  131. if (session_readonly())
  132. return;
  133. return parent::DispList($qrow,$form);
  134. }
  135. public function DispAddEdit($val,&$form){
  136. if (session_readonly())
  137. return;
  138. return parent::DispAddEdit($val,$form);
  139. }
  140. public function buildInsert(&$ins_arr,&$form){
  141. if (session_readonly())
  142. return;
  143. return parent::buildInsert($ins_arr,$form);
  144. }
  145. public function buildUpdate(&$ins_arr,&$form){
  146. if (session_readonly())
  147. return;
  148. return parent::buildUpdate($ins_arr,$form);
  149. }
  150. public function renderSpecial(array &$qrow,&$form,$rmode, &$robj){
  151. if (session_readonly())
  152. return;
  153. return parent::renderSpecial($qrow,$form,$rmode, $robj);
  154. }
  155. public function detailQueryField(&$dbhandle){
  156. if (session_readonly())
  157. return;
  158. return parent::detailQueryField($dbhandle);
  159. }
  160. public function editQueryField(&$dbhandle){
  161. if (session_readonly())
  162. return;
  163. return parent::editQueryField($dbhandle);
  164. }
  165. };
  166. ?>