PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/functions/Inputs.php

https://gitlab.com/gregtyka/opensis
PHP | 264 lines | 222 code | 37 blank | 5 comment | 61 complexity | 8a2f7d77efd8f37e9f304a4553e156cb MD5 | raw file
  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",true,array('Y'=>1,'M'=>1,'D'=>1))).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."\",\"div$name\",true)'>".(($value!='')?ProperDate($value):'-').($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. $value = str_replace("'",'&#39;',str_replace('"','&rdquo;',$value));
  24. $value1 = is_array($value) ? $value[1] : $value;
  25. $value = is_array($value) ? $value[0] : $value;
  26. if(strpos($options,'size')===false && $value!='')
  27. $options .= ' size='.strlen($value);
  28. elseif(strpos($options,'size')===false)
  29. $options .= ' size=10';
  30. if((trim($value)=='' || $div==false))
  31. return "<INPUT type=text name=$name ".(($value || $value==='0')?"value=\"$value\"":'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  32. else
  33. return "<DIV id='div$name'><div onclick='javascript:addHTML(\"<INPUT type=text id=input$name name=$name ".(($value || $value==='0')?"value=\\\"".str_replace('"','&rdquo;',$value)."\\\"":'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."\",\"div$name\",true); document.getElementById(\"input$name\").focus();'>".(($value!='')?str_replace('"','&rdquo;',$value1):'-').($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>';
  34. }
  35. else
  36. 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>':'');
  37. }
  38. function TextAreaInput($value,$name,$title='',$options='',$div=true)
  39. {
  40. if(Preferences('HIDDEN')!='Y')
  41. $div = false;
  42. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  43. {
  44. $value = str_replace("'",'&#39;',str_replace('"','&rdquo;',$value));
  45. if(strpos($options,'cols')===false)
  46. $options .= ' cols=30';
  47. if(strpos($options,'rows')===false)
  48. $options .= ' rows=4';
  49. $rows = substr($options,strpos($options,'rows')+5,2)*1;
  50. $cols = substr($options,strpos($options,'cols')+5,2)*1;
  51. if($value=='' || $div==false)
  52. 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>':'');
  53. else
  54. 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("'","&#39;",$value)))."</TEXTAREA>".($title!=''?"<BR><small>".str_replace("'",'&#39;',(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$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 ><TR><TD>".((substr_count($value,"\r\n")>$rows)?'<DIV style="overflow:auto; height:'.(15*$rows).'px; width:'.($cols*10).'; padding-right: 16px;">'.nl2br($value).'</DIV>':'<DIV style="overflow:auto; width:300; padding-right: 16px;">'.nl2br($value).'</DIV>').'</TD></TR></TABLE>'.($title!=''?'<BR><small>'.str_replace("'",'&#39;',(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'')).'</small>':'').'</div></DIV>';
  55. }
  56. else
  57. return (($value!='')?nl2br($value):'-').($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  58. }
  59. function CheckboxInput($value,$name,$title='',$checked='',$new=false,$yes='Yes',$no='No',$div=true,$extra='')
  60. {
  61. // $checked has been deprecated -- it remains only as a placeholder
  62. if(Preferences('HIDDEN')!='Y')
  63. $div = false;
  64. if($div==false || $new==true)
  65. {
  66. if($value && $value!='N')
  67. $checked = 'CHECKED';
  68. else
  69. $checked = '';
  70. }
  71. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  72. {
  73. if($new || $div==false)
  74. 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>':'');
  75. else
  76. 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>'.str_replace("'",'&#39;',(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'')).'</small>':'')."\",\"div$name\",true)'>".($value?$yes:$no).($title!=''?"<BR><small>".str_replace("'",'&#39;',(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':''))."</small>":'')."</div></DIV>";
  77. }
  78. else
  79. return ($value?$yes:$no).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  80. }
  81. function SelectInput($value,$name,$title='',$options,$allow_na='N/A',$extra='',$div=true)
  82. {
  83. if(Preferences('HIDDEN')!='Y')
  84. $div = false;
  85. // mab - support array style $option values
  86. // mab - append current val to select list if not in list
  87. if ($value!='' && !$options[$value])
  88. $options[$value] = array($value,'<FONT color=red>'.$value.'</FONT>');
  89. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  90. {
  91. if($value!='' && $div)
  92. {
  93. $return = "<DIV id='div$name'><div onclick='javascript:addHTML(\"";
  94. $extra = str_replace('"','\"',$extra);
  95. }
  96. $return .= "<SELECT name=$name $extra>";
  97. if($allow_na!==false)
  98. {
  99. if($value!='' && $div)
  100. $return .= '<OPTION value=\"\">'.$allow_na;
  101. else
  102. $return .= '<OPTION value="">'.$allow_na;
  103. }
  104. if(count($options))
  105. {
  106. foreach($options as $key=>$val)
  107. {
  108. settype($key,'string');
  109. if($value!='' && $div)
  110. $return .= "<OPTION value=\\\"".str_replace("'",'&#39;',$key)."\\\" ".(($value==$key && (!($value==false && ($value!==$key)) || ($value==='0' && $key===0)))?'SELECTED':'').">".str_replace("'",'&#39;',(is_array($val)?$val[0]:$val));
  111. else
  112. $return .= "<OPTION value=\"$key\" ".(($value==$key && !($value==false && $value!==$key))?'SELECTED':'').">".(is_array($val)?$val[0]:$val);
  113. }
  114. }
  115. $return .= "</SELECT>";
  116. if($title!='')
  117. $return .= '<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'<FONT>':'').'</small>';
  118. if($value!='' && $div)
  119. $return .="\",\"div$name\",true)'>".(is_array($options[$value])?$options[$value][1]:$options[$value]).($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'').'</div></DIV>';
  120. }
  121. else
  122. $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>':'');
  123. return $return;
  124. }
  125. function NoInput($value,$title='')
  126. {
  127. return ($value!=''?$value:'-').($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  128. }
  129. function TextInputSchool($value,$name,$title='',$options='',$div=true)
  130. {
  131. if(Preferences('HIDDEN')!='Y')
  132. $div = false;
  133. // mab - support array style $option values
  134. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  135. {
  136. $value = str_replace("'",'&#39;',str_replace('"','&rdquo;',$value));
  137. $value1 = is_array($value) ? $value[1] : $value;
  138. $value = is_array($value) ? $value[0] : $value;
  139. if(strpos($options,'size')===false && $value!='')
  140. $options .= ' size='.strlen($value);
  141. elseif(strpos($options,'size')===false)
  142. $options .= 'type=\'text\' class=\"cell_wide\"';
  143. if((trim($value)=='' || $div==false))
  144. return "<INPUT type=text name=$name ".(($value || $value==='0')?"value=\"$value\"":'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  145. else
  146. return "<DIV id='div$name'><div onclick='javascript:addHTML(\"<INPUT type=text id=input$name name=$name ".(($value || $value==='0')?"value=\\\"".str_replace('"','&rdquo;',$value)."\\\"":'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."\",\"div$name\",true); document.getElementById(\"input$name\").focus();'>".(($value!='')?str_replace('"','&rdquo;',$value1):'-').($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>';
  147. }
  148. else
  149. 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>':'');
  150. }
  151. function ModTextInput($value,$name,$title='',$options='',$div=true)
  152. {
  153. // mab - support array style $option values
  154. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  155. {
  156. $value = str_replace("'",'&#39;',str_replace('"','&rdquo;',$value));
  157. $value1 = is_array($value) ? $value[1] : $value;
  158. $value = is_array($value) ? $value[0] : $value;
  159. if(strpos($options,'size')===false && $value!='')
  160. $options .= ' size='.strlen($value);
  161. elseif(strpos($options,'size')===false)
  162. $options .= ' size=10';
  163. if((trim($value)=='' || $div==false))
  164. return "<INPUT type=text name=$name ".(($value || $value==='0')?"value=\"$value\"":'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  165. else
  166. return "<INPUT type=text name=$name ".(($value || $value==='0')?"value=\"$value\"":'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  167. }
  168. else
  169. 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>':'');
  170. }
  171. function TextInputWrap($value,$name,$title='',$options='',$div=true, $wrap='')
  172. {
  173. if(Preferences('HIDDEN')!='Y')
  174. $div = false;
  175. // mab - support array style $option values
  176. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  177. {
  178. $value = str_replace("'",'&#39;',str_replace('"','&rdquo;',$value));
  179. $value1 = is_array($value) ? $value[1] : $value;
  180. $value = is_array($value) ? $value[0] : $value;
  181. if(strpos($options,'size')===false && $value!='')
  182. $options .= ' size='.strlen($value);
  183. elseif(strpos($options,'size')===false)
  184. $options .= ' size=10';
  185. else
  186. $options .= ' size=10 class=cell_floating';
  187. if((trim($value)=='' || $div==false))
  188. return "<INPUT type=text name=$name ".(($value || $value==='0')?"value=\"$value\"":'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  189. else
  190. return "<DIV id='div$name' STYLE='word-wrap:break-word; width:".$wrap."px; overflow:auto'><div onclick='javascript:addHTML(\"<INPUT type=text id=input$name name=$name ".(($value || $value==='0')?"value=\\\"".str_replace('"','&rdquo;',$value)."\\\"":'')." $options>".($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'')."\",\"div$name\",true); document.getElementById(\"input$name\").focus();'>".(($value!='')?str_replace('"','&rdquo;',$value1):'-').($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>';
  191. }
  192. else
  193. 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>':'');
  194. }
  195. function TextAreaInputWrap($value,$name,$title='',$options='',$div=true, $wrap='')
  196. {
  197. if(Preferences('HIDDEN')!='Y')
  198. $div = false;
  199. if(AllowEdit() && !$_REQUEST['_CENTRE_PDF'])
  200. {
  201. $value = str_replace("'",'&#39;',str_replace('"','&rdquo;',$value));
  202. if(strpos($options,'cols')===false)
  203. $options .= ' cols=70';
  204. if(strpos($options,'rows')===false)
  205. $options .= ' rows=8';
  206. $rows = substr($options,strpos($options,'rows')+5,2)*1;
  207. $cols = substr($options,strpos($options,'cols')+5,2)*1;
  208. if($value=='' || $div==false)
  209. 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>':'');
  210. else
  211. return "<DIV id='div$name' STYLE='word-wrap:break-word; '><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("'","&#39;",$value)))."</TEXTAREA>".($title!=''?"<BR><small>".str_replace("'",'&#39;',(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$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 ><TR><TD>".((substr_count($value,"\r\n")>$rows)?'<DIV style="overflow:auto; height:'.(15*$rows).'px; width:'.($cols*10).'; padding-right: 16px;">'.nl2br($value).'</DIV>':'<DIV style="overflow:auto; width:300; padding-right: 16px;">'.nl2br($value).'</DIV>').'</TD></TR></TABLE>'.($title!=''?'<BR><small>'.str_replace("'",'&#39;',(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'')).'</small>':'').'</div></DIV>';
  212. }
  213. else
  214. return (($value!='')?nl2br($value):'-').($title!=''?'<BR><small>'.(strpos(strtolower($title),'<font ')===false?'<FONT color='.Preferences('TITLES').'>':'').$title.(strpos(strtolower($title),'<font ')===false?'</FONT>':'').'</small>':'');
  215. }
  216. ?>