PageRenderTime 51ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/functions/Inputs.php

https://github.com/saakaifoundry/centreSIS
PHP | 285 lines | 267 code | 14 blank | 4 comment | 64 complexity | 876e21ad4400dccf1cf6f5ae1838aaf9 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. function DateInput($value,$name,$title='',$div=true,$allow_na=true)
  3. {
  4. if(Preferences('HIDDEN')!='Y')
  5. $div = false;
  6. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  7. {
  8. if($value=='' || $div==false)
  9. return PrepareDate($value,"_$name",$allow_na).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  10. else
  11. return "<DIV id='div$name'><div onclick='javascript:addHTML(\"".str_replace('"','\"',PrepareDate($value,"_$name",$allow_na,array('Y'=>1,'M'=>1,'D'=>1))).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').str_replace(array("'",'"'),array('&#39;','\"'),$title).(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."\",\"div$name\",true)'><span style='border-bottom-style:dotted;border-bottom-width:1;border-bottom-color:".Preferences('TITLES').";'>".($value!=''?ProperDate($value):'-').'</span>'.($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'').'</div></DIV>';
  12. }
  13. else
  14. return ($value!=''?ProperDate($value):'-').($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  15. }
  16. function TextInput($value,$name,$title='',$options='',$div=true)
  17. {
  18. if(Preferences('HIDDEN')!='Y')
  19. $div = false;
  20. // mab - support array style $option values
  21. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  22. {
  23. $value1 = is_array($value) ? $value[1] : $value;
  24. $value = is_array($value) ? $value[0] : $value;
  25. if(strpos($options,'size')===false && $value!='')
  26. $options .= ' size='.strlen($value);
  27. elseif(strpos($options,'size')===false)
  28. $options .= ' size=10';
  29. if(trim($value)=='' || $div==false)
  30. return "<INPUT type=text name=$name ".($value || $value==='0'?'value="'.str_replace('"','&quot;',$value).'"':'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  31. else
  32. return "<DIV id='div$name'><div onclick='javascript:addHTML(\"<INPUT type=text id=input$name name=$name ".($value||$value==='0'?'value=\"'.str_replace(array("'",'"'),array('&#39;','&rdquo;'),$value).'\"':'').' '.$options.'>'.($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').str_replace(array("'",'"'),array('&#39;','\"'),$title).(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."\",\"div$name\",true); document.getElementById(\"input$name\").focus();'><span style='border-bottom-style:dotted;border-bottom-width:1;border-bottom-color:".Preferences('TITLES').";'>".($value!=''?$value1:'-').'</span>'.($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').'</small>':'').'</div></DIV>';
  33. }
  34. else
  35. return (((is_array($value)?$value[1]:$value)!='')?(is_array($value)?$value[1]:$value):'-').($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  36. }
  37. function MLTextInput($value,$name,$title='',$options='',$div=true)
  38. { global $CentreLocales;
  39. if (sizeof($CentreLocales) < 2)
  40. return TextInput($value,$name,$title,$options,$div);
  41. if(Preferences('HIDDEN')!='Y')
  42. $div = false;
  43. // mab - support array style $option values
  44. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  45. {
  46. $value1 = is_array($value) ? $value[1] : $value;
  47. $value = is_array($value) ? $value[0] : $value;
  48. if(strpos($options,'size')===false && $value!='')
  49. $options .= ' size='.strlen($value);
  50. elseif(strpos($options,'size')===false)
  51. $options .= ' size=10';
  52. // ng - foreach possible language
  53. $ret = "<DIV><INPUT type=hidden id=$name name=$name value='$value'>";
  54. foreach ($CentreLocales as $id=>$loc) {
  55. $ret .= "<IMG src='assets/flags/$loc.png' height=20px width=20px />";
  56. $ret .= TextInput(ParseMLField($value, $loc),'ML_'.$name.'['.$loc.']','',$options." onchange=\"javascript:setMLvalue('$name','".($id==0?'':$loc)."',this.value);\"",false);
  57. $ret .= "<BR>";
  58. }
  59. $ret .= "</DIV>";
  60. }
  61. $ret .= ($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  62. return $ret;
  63. }
  64. function TextAreaInput($value,$name,$title='',$options='',$div=true)
  65. {
  66. if(Preferences('HIDDEN')!='Y')
  67. $div = false;
  68. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  69. {
  70. if(strpos($options,'cols')===false)
  71. $options .= ' cols=30';
  72. if(strpos($options,'rows')===false)
  73. $options .= ' rows=4';
  74. $rows = substr($options,strpos($options,'rows')+5,2)*1;
  75. $cols = substr($options,strpos($options,'cols')+5,2)*1;
  76. if($value=='' || $div==false)
  77. return "<TEXTAREA name=$name $options>$value</TEXTAREA>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  78. else
  79. return "<DIV id='div$name'><div onclick='javascript:addHTML(\"<TEXTAREA id=textarea$name name=$name $options>".ereg_replace("[\n\r]",'\u000D\u000A',str_replace("\r\n",'\u000D\u000A',str_replace(array("'",'"'),array('&#39;','\"'),$value)))."</TEXTAREA>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').str_replace(array("'",'"'),array('&#39;','\"'),$title).(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."\",\"div$name\",true); document.getElementById(\"textarea$name\").value=unescape(document.getElementById(\"textarea$name\").value);'><TABLE class=LO_field height=100%><TR><TD>".((substr_count($value,"\r\n")>$rows)?'<DIV style="overflow:auto; height:'.(15*$rows).'px; width:'.($cols*9).'; padding-right: 16px;border-bottom-style:dotted;border-bottom-width:1;border-bottom-color:'.Preferences('TITLES').';">'.nl2br($value).'</DIV>':'<DIV style="overflow:auto; width:'.($cols*9).'; padding-right: 16px;border-bottom-style:dotted;border-bottom-width:1;border-bottom-color:'.Preferences('TITLES').';">'.nl2br($value).'</DIV>').'</TD></TR></TABLE>'.($title!=''?'<small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'').'</div></DIV>';
  80. }
  81. else
  82. return ($value!=''?nl2br($value):'-').($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  83. }
  84. function CheckboxInput($value,$name,$title='',$checked='',$new=false,$yes='Yes',$no='No',$div=true,$extra='')
  85. {
  86. // $checked has been deprecated -- it remains only as a placeholder
  87. if(Preferences('HIDDEN')!='Y')
  88. $div = false;
  89. if($div==false || $new==true)
  90. {
  91. if($value && $value!='N')
  92. $checked = 'CHECKED';
  93. else
  94. $checked = '';
  95. }
  96. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  97. {
  98. if($new || $div==false)
  99. return "<INPUT type=checkbox name=$name value=Y $checked $extra>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  100. else
  101. return "<DIV id='div$name'><div onclick='javascript:addHTML(\"<INPUT type=hidden name=$name value=\\\"\\\"><INPUT type=checkbox name=$name ".($value?'checked':'')." value=Y ".str_replace('"','\"',$extra).">".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').str_replace(array("'",'"'),array('&#39;','\"'),$title).(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."\",\"div$name\",true)'><span style='border-bottom-style:dotted;border-bottom-width:1;border-bottom-color:".Preferences('TITLES').";'>".($value?$yes:$no).'</span>'.($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."</div></DIV>";
  102. }
  103. else
  104. return ($value?$yes:$no).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  105. }
  106. function SelectInput($value,$name,$title='',$options,$allow_na='N/A',$extra='',$div=true)
  107. {
  108. if(Preferences('HIDDEN')!='Y')
  109. $div = false;
  110. // mab - support array style $option values
  111. // mab - append current val to select list if not in list
  112. if ($value!='' && $options[$value]=='')
  113. $options[$value] = array($value,'<FONT color=red>'.$value.'</FONT>');
  114. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  115. {
  116. if($value!='' && $div)
  117. {
  118. $return = "<DIV id='div$name'><div onclick='javascript:addHTML(\"";
  119. $extra = str_replace('"','\"',$extra);
  120. }
  121. $return .= "<SELECT name=$name $extra>";
  122. if($allow_na!==false)
  123. {
  124. if($value!='' && $div)
  125. $return .= '<OPTION value=\"\">'.$allow_na;
  126. else
  127. $return .= '<OPTION value="">'.$allow_na;
  128. }
  129. if(count($options))
  130. {
  131. foreach($options as $key=>$val)
  132. {
  133. $key .= '';
  134. if($value!='' && $div)
  135. $return .= '<OPTION value=\"'.str_replace(array("'",'"'),array('&#39;','&rdquo;'),$key).'\"'.($value==$key && (!($value==false && $value!==$key) || ($value===0 && $key==='0'))?' SELECTED':'').'>'.str_replace(array("'",'"'),array('&#39;','\"'),(is_array($val)?$val[0]:$val));
  136. else
  137. $return .= '<OPTION value="'.$key.'"'.($value==$key && (!($value==false && $value!==$key) || ($value===0 && $key==='0'))?' SELECTED':'').'>'.(is_array($val)?$val[0]:$val);
  138. }
  139. }
  140. $return .= "</SELECT>";
  141. if($title!='')
  142. $return .= '<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').str_replace(array("'",'"'),array('&#39;','\"'),$title).(strpos(strtolower($title),'<font ')===false?'<FONT>':'').'</small>';
  143. if($value!='' && $div)
  144. $return .="\",\"div$name\",true)'><span style='border-bottom-style:dotted;border-bottom-width:1;border-bottom-color:".Preferences('TITLES').";'>".(is_array($options[$value])?$options[$value][1]:$options[$value]).'</span>'.($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'').'</div></DIV>';
  145. }
  146. else
  147. $return = (((is_array($options[$value])?$options[$value][1]:$options[$value])!='')?(is_array($options[$value])?$options[$value][1]:$options[$value]):($allow_na!==false?($allow_na?$allow_na:'-'):'-')).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  148. return $return;
  149. }
  150. function MLSelectInput($value,$name,$title='',$options,$allow_na='N/A',$extra='',$div=true)
  151. {
  152. global $CentreLocales, $locale;
  153. if (sizeof($CentreLocales) < 2)
  154. return SelectInput($value,$name,$title,$options,$div);
  155. if(Preferences('HIDDEN')!='Y')
  156. $div = false;
  157. // mab - support array style $option values
  158. // mab - append current val to select list if not in list
  159. if ($value!='' && $options[$value]=='')
  160. $options[$value] = array($value,'<FONT color=red>'.$value.'</FONT>');
  161. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  162. {
  163. if($value!='' && $div)
  164. {
  165. $return = "<DIV id='div$name'><div onclick='javascript:addHTML(\"";
  166. $extra = str_replace('"','\"',$extra);
  167. }
  168. $return .= "<SELECT name=$name $extra>";
  169. if($allow_na!==false)
  170. {
  171. if($value!='' && $div)
  172. $return .= '<OPTION value=\"\">'.$allow_na;
  173. else
  174. $return .= '<OPTION value="">'.$allow_na;
  175. }
  176. if(count($options))
  177. {
  178. foreach($options as $key=>$val)
  179. {
  180. $key .= '';
  181. if($value!='' && $div)
  182. $return .= '<OPTION value=\"'.str_replace(array("'",'"'),array('&#39;','&rdquo;'),$key).'\"'.($value==$key && (!($value==false && $value!==$key) || ($value===0 && $key==='0'))?' SELECTED':'').'>'.str_replace(array("'",'"'),array('&#39;','\"'),(is_array($val)?ParseMLField($val[0], $locale):ParseMLField($val, $locale)));
  183. else
  184. $return .= '<OPTION value="'.$key.'"'.($value==$key && (!($value==false && $value!==$key) || ($value===0 && $key==='0'))?' SELECTED':'').'>'.(is_array($val)?ParseMLField($val[0], $locale):ParseMLField($val, $locale));
  185. }
  186. }
  187. $return .= "</SELECT>";
  188. if($title!='')
  189. $return .= '<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').str_replace(array("'",'"'),array('&#39;','\"'),$title).(strpos(strtolower($title),'<font ')===false?'<FONT>':'').'</small>';
  190. if($value!='' && $div)
  191. $return .="\",\"div$name\",true)'><span style='border-bottom-style:dotted;border-bottom-width:1;border-bottom-color:".Preferences('TITLES').";'>".ParseMLField((is_array($options[$value])?$options[$value][1]:$options[$value]), $locale).'</span>'.($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'').'</div></DIV>';
  192. }
  193. else
  194. $return = ParseMLField((((is_array($options[$value])?$options[$value][1]:$options[$value])!='')?(is_array($options[$value])?$options[$value][1]:$options[$value]):($allow_na!==false?($allow_na?$allow_na:'-'):'-')),$locale).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  195. return $return;
  196. }
  197. function RadioInput($value,$name,$title='',$options,$allow_na='N/A',$extra='',$div=true)
  198. {
  199. if(Preferences('HIDDEN')!='Y')
  200. $div = false;
  201. if ($value!='' && $options[$value]=='')
  202. $options[$value] = array($value,'<FONT color=red>'.$value.'</FONT>');
  203. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  204. {
  205. if($value!='' && $div)
  206. {
  207. $return = "<DIV id='div$name'><div onclick='javascript:addHTML(\"";
  208. $extra = str_replace('"','\"',$extra);
  209. }
  210. $return .= '<TABLE cellspacing=0 cellpadding=0><TR align=center>';
  211. if($allow_na!==false)
  212. {
  213. if($value!='' && $div)
  214. $return .= '<TD><INPUT type=radio name='.$name.' value=\"\"'.($value==''?' CHECKED':'').'><BR><small>'.$allow_na.'</small></TD><TD>&nbsp;</TD>';
  215. else
  216. $return .= '<TD><INPUT type=radio name='.$name.' value=""'.($value==''?' CHECKED':'').'><BR><small>'.$allow_na.'</small></TD><TD>&nbsp;</TD>';
  217. }
  218. if(count($options))
  219. {
  220. foreach($options as $key=>$val)
  221. {
  222. $key .= '';
  223. if($value!='' && $div)
  224. $return .= '<TD><INPUT type=radio name=$name value=\"'.str_replace(array("'",'"'),array('&#39;','&rdquo;'),$key).'\" '.($value==$key && (!($value==false && $value!==$key) || ($value==='0' && $key===0))?'CHECKED':'').'><BR><small>'.str_replace(array("'",'"'),array('&#39;','\"'),(is_array($val)?$val[0]:$val)).'</small></TD><TD>&nbsp;</TD>';
  225. else
  226. $return .= "<TD><INPUT type=radio name=$name value=\"$key\" ".(($value==$key && !($value==false && $value!==$key))?'CHECKED':'').'><BR><small>'.(is_array($val)?$val[0]:$val).'</small></TD><TD>&nbsp;</TD>';
  227. }
  228. }
  229. $return .= '</TR></TABLE>';
  230. if($title!='')
  231. $return .= '<small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'<FONT>':'').'</small>';
  232. if($value!='' && $div)
  233. $return .="\",\"div$name\",true)'><span style='border-bottom-style:dotted;border-bottom-width:1;border-bottom-color:".Preferences('TITLES').";'>".(is_array($options[$value])?$options[$value][1]:$options[$value]).'</span>'.($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'').'</div></DIV>';
  234. }
  235. else
  236. $return = (((is_array($options[$value])?$options[$value][1]:$options[$value])!='')?(is_array($options[$value])?$options[$value][1]:$options[$value]):($allow_na!==false?($allow_na?$allow_na:'-'):'-')).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  237. return $return;
  238. }
  239. function NoInput($value,$title='')
  240. {
  241. return ($value!=''?$value:'-').($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  242. }
  243. function CheckBoxOnclick($name)
  244. {
  245. return '<INPUT type=checkbox name='.$name.' value=Y'.($_REQUEST[$name]=='Y'?" CHECKED onclick='document.location.href=\"".PreparePHP_SELF($_REQUEST,array(),array($name=>''))."\";'":" onclick='document.location.href=\"".PreparePHP_SELF($_REQUEST,array(),array($name=>'Y'))."\";'").'>';
  246. }
  247. ?>