00001 <?PHP
00028 class ClientProxy
00029 {
00030 protected $m_RequestArgs;
00031 protected $m_FormInputArray = null;
00032 protected $m_bRPCFlag = false;
00033
00039 private $_formsOutput = array();
00040 private $_otherOutput = array();
00041
00047 private $_extraScripts = array();
00048
00054 private $_extraStyles = array();
00055
00065 public function hasFormRerendered($formName)
00066 {
00067 return array_key_exists($formName, $this->_formsOutput);
00068 }
00069
00076 public function getFormOutput ($formName)
00077 {
00078 return $this->_formsOutput[$formName];
00079 }
00080
00087 public function hasOtherOutput()
00088 {
00089 return count($this->_otherOutput) > 0;
00090 }
00091
00097 public function hasOutput()
00098 {
00099 return count($this->_otherOutput) + count($this->_formsOutput) > 0;
00100 }
00101
00107 public function printOutput()
00108 {
00109 if ($this->m_bRPCFlag == true)
00110 return $this->printJSONOuput();
00111
00112 foreach ($this->_otherOutput as $output)
00113 print $output;
00114 foreach ($this->_formsOutput as $output)
00115 print $output;
00116 }
00117
00118 protected function printJSONOuput()
00119 {
00120 $outs = array();
00121
00122 foreach ($this->_otherOutput as $output)
00123 $outs[] = $output;
00124 foreach ($this->_formsOutput as $output)
00125 $outs[] = $output;
00126 if (function_exists("json_encode"))
00127 echo json_encode($outs);
00128 else
00129 {
00130 require_once 'Zend/Json.php';
00131 echo Zend_Json::encode($outs);
00132 }
00133 }
00134
00141 public function setRPCFlag($flag)
00142 {
00143 $this->m_bRPCFlag = $flag;
00144 }
00145
00154 public function getRequestParam($name)
00155 {
00156 $val = (isset($_REQUEST[$name]) ? $_REQUEST[$name] : "");
00157 return $val;
00158 }
00159
00167 public function getFormInputs($controlName = null, $toString = TRUE)
00168 {
00169 if ($controlName)
00170 {
00171 if (isset($_GET[$controlName]))
00172 {
00173 $_POST[$controlName] = $_GET[$controlName];
00174 }
00175 if (isset($_POST[$controlName]))
00176 {
00177 if (is_array($_POST[$controlName]) and $toString == TRUE)
00178 {
00179 $array_string = '';
00180 foreach ($_POST[$controlName] as $rec)
00181 {
00182 $array_string .= $rec . ",";
00183 }
00184 $result = substr($array_string, 0, strlen($array_string) - 1);
00185 }
00186 else
00187 {
00188 $result = $_POST[$controlName];
00189 }
00190 if (get_magic_quotes_gpc() == 1)
00191 {
00192 if (!is_array($result))
00193 $result = stripslashes($result);
00194 }
00195 return $result;
00196 }
00197 else
00198 {
00199 if(isset($_FILES[$controlName])){
00200 $result =true;
00201 return $result;
00202 }else{
00203 return null;
00204 }
00205 }
00206 }
00207 else
00208 {
00209 return $_POST;
00210 }
00211 }
00212
00221 public function updateFormElements($formName, $recArr, $rawData=false)
00222 {
00223 if ($this->m_bRPCFlag)
00224 {
00225 if ($rawData)
00226 {
00227 $fieldsOutput = $recArr;
00228 $this->_otherOutput[] = $this->_buildTargetContent($formName,$fieldsOutput);
00229 }
00230 else
00231 {
00232 foreach ($recArr as $fld => $val)
00233 $fieldsOutput[] = $this->_buildTargetContent($fld,$val);
00234 $this->_otherOutput[] = $this->_buildTargetContent($formName,$fieldsOutput);
00235 }
00236 }
00237 }
00238
00248 public function redrawForm($formName, $sHTML)
00249 {
00250 if ($this->m_bRPCFlag)
00251 $this->_formsOutput[$formName] = $this->_buildTargetContent($formName, $sHTML);
00252 else
00253 $this->_formsOutput[$formName] = $sHTML;
00254 }
00255
00263 public function showClientAlert($alertText)
00264 {
00265 $msg = addslashes($alertText);
00266 if ($this->m_bRPCFlag)
00267 $this->_otherOutput[] = $this->_callClientFunction("alert('" . $msg . "')");
00268 }
00269
00279 public function showErrorMessage ($errMsg, $flush=false)
00280 {
00281 if(!$errMsg){
00282 return;
00283 }
00284 if ($this->m_bRPCFlag)
00285 {
00286 $this->_otherOutput[] = $this->_buildTargetContent("ERROR", $errMsg);
00287 if ($flush) {
00288 $this->printOutput();
00289 exit;
00290 }
00291 }
00292 else
00293 {
00294 $this->_errorOutput($errMsg);
00295 }
00296 }
00297
00306 public function showPopup($baseForm, $popupForm, $ctrlName = "")
00307 {
00308 if ($this->m_bRPCFlag)
00309 {
00310 $function = $baseForm . ".ShowPopup(" . $popupForm . "," . $ctrlName . ")";
00311 $this->_otherOutput[] = $this->_callClientFunction("CallFunction('$function','Popup')");
00312 }
00313 }
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00337 private function _errorOutput ($errMsg)
00338 {
00339
00340 if(defined('INTERNAL_ERROR_VIEW')){
00341
00342 $_GET['ob_err_msg']=$errMsg;
00343 ob_end_clean();
00344 BizSystem::getObject(INTERNAL_ERROR_VIEW)->render();
00345 exit;
00346 }
00347 else
00348 {
00349 echo $errMsg;
00350 echo "<input type='button' NAME='btn_back' VALUE='Go back' onClick='history.go(-1);return true;'>";
00351 }
00352 }
00353
00359 public function closePopup()
00360 {
00361 if ($this->m_bRPCFlag){
00362 $this->_formsOutput[] = $this->_callClientFunction("Openbiz.Window.closePopup()");
00363 $this->_otherOutput[] = $this->_callClientFunction("Openbiz.Window.closePopup()");
00364 }
00365 }
00366
00375 public function showPopupWindow ($content, $w, $h)
00376 {
00377 if ($this->m_bRPCFlag)
00378 $this->_formsOutput[] = $this->_callClientFunction("popupWindow(\"$content\", $w, $h)");
00379 }
00380
00388 public function updateClientElement($elementId, $content)
00389 {
00390 $scriptStr = "<script>$('".$elementId."').innerHTML='".$content."';</script>";
00391 $this->runClientScript($scriptStr);
00392 }
00393
00400 public function runClientScript($scriptStr)
00401 {
00402 if ($this->m_bRPCFlag)
00403 $this->_otherOutput[] = $this->_buildTargetContent("SCRIPT", $scriptStr);
00404 else
00405 {
00406 echo $script;
00407 }
00408 }
00409
00410 public function runClientFunction($scriptStr)
00411 {
00412 $msg = addslashes($alertText);
00413 if ($this->m_bRPCFlag)
00414 $this->_otherOutput[] = $this->_callClientFunction($scriptStr);
00415 }
00416
00423 private function _callClientFunction ($funcStr)
00424 {
00425 if ($this->m_bRPCFlag)
00426 return $this->_buildTargetContent("FUNCTION", $funcStr);
00427 }
00428
00437 private function _buildTargetContent($tgt, &$ctnt)
00438 {
00439 return array('target'=>$tgt, 'content'=>$ctnt);
00440 }
00441
00450 public function redirectPage($pageURL)
00451 {
00452 if (!$this->m_bRPCFlag)
00453 {
00454 ob_clean();
00455 header("Location: $pageURL");
00456 return;
00457 }
00458 if ($pageURL == "#back")
00459 $this->_otherOutput[] = $this->_callClientFunction("history.go(-1)");
00460 else
00461 $this->_otherOutput[] = $this->_callClientFunction("Openbiz.Net.redirectPage('$pageURL')");
00462 }
00463
00472 public function redirectView($view, $rule=null)
00473 {
00474 if (!$this->m_bRPCFlag)
00475 {
00476 ob_clean();
00477 header("Location: controller.php?view=$view");
00478 return;
00479 }
00480 $this->_otherOutput[] = $this->_callClientFunction("GoToView('$view','$rule')");
00481 }
00482
00491 public function appendScripts ($scriptKey, $scripts, $isFile = true)
00492 {
00493
00494 if (isset($this->_extraScripts[$scriptKey]))
00495 return;
00496
00497 if ($isFile)
00498 {
00499 $_scripts = "<script type='text/javascript' src=\"".Resource::getJsUrl()."/$scripts\"></script>";
00500 $this->_extraScripts[$scriptKey] = $_scripts;
00501 } else
00502 $this->_extraScripts[$scriptKey] = $scripts;
00503 }
00504
00510 public function getAppendedScripts()
00511 {
00512 $currentView = BizSystem::instance()->getCurrentViewName();
00513 $initScripts = "<script>var APP_URL='".APP_URL."'; var APP_CONTROLLER='".APP_URL."/bin/controller.php';</script>\n";
00514 $initScripts .= "<script>var APP_VIEWNAME='".$currentView."';</script>\n";
00515 $extraScripts = implode("", $this->_extraScripts);
00516 $extraScript_array = explode("</script>", $extraScripts);
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529 $cleanScript_array = array();
00530 foreach ($extraScript_array as $script)
00531 {
00532 if (in_array($script . "</script>", $cleanScript_array) == FALSE and strlen($script) != 0)
00533 $cleanScript_array[] = $script . "</script>";
00534 }
00535 return $initScripts.implode("\n", $cleanScript_array);
00536 }
00537
00546 public function appendStyles($scriptKey, $styles, $isFile = true)
00547 {
00548
00549 if (isset($this->_extraStyles[$scriptKey]))
00550 return;
00551
00552 $css = Resource::getCssUrl();
00553 if ($isFile)
00554 {
00555 $_styles = "<link rel=\"stylesheet\" href=\"$css/" . $styles . "\" type=\"text/css\">";
00556 $this->_extraStyles[$scriptKey] = $_styles;
00557 } else
00558 $this->_extraStyles[$scriptKey] = $styles;
00559 }
00560
00566 public function getAppendedStyles($comb=0)
00567 {
00568 $extraStyles = implode("", $this->_extraStyles);
00569 $extraStyle_array = explode("type=\"text/css\">", $extraStyles);
00570 if (defined("RESOURCE_PHP") && $comb) {
00571 $css_scripts = RESOURCE_PHP."?f=";
00572 foreach ($extraStyle_array as $style)
00573 {
00574
00575 if (preg_match('/.+href="([^"]+)".+/', $style, $matches) > 0 && !empty($matches[1])) {
00576 if (substr($css_scripts, -2)=='f=') $css_scripts .= $matches[1];
00577 else $css_scripts .= ','.$matches[1];
00578 }
00579 }
00580 return "<link rel=\"stylesheet\" href=\"".$css_scripts."\" type=\"text/css\"/>";
00581 }
00582 $cleanStyle_array = array();
00583 foreach ($extraStyle_array as $style)
00584 {
00585 if (in_array($style . "type=\"text/css\">", $cleanStyle_array) == FALSE and strlen($style) != 0)
00586 $cleanStyle_array[] = $style . "type=\"text/css\">";
00587 }
00588
00589
00590 $lang = I18n::getCurrentLangCode();
00591 $localization_css_file = APP_HOME.DIRECTORY_SEPARATOR."languages".DIRECTORY_SEPARATOR.$lang.DIRECTORY_SEPARATOR."localization.css";
00592 if(is_file($localization_css_file)){
00593 $cleanStyle_array[] = "<link rel=\"stylesheet\" href=\"".APP_URL."/languages/$lang/localization.css\" type=\"text/css\">";
00594 }
00595 return implode("\n", $cleanStyle_array);
00596 }
00597
00603 public function includeCalendarScripts()
00604 {
00605 if (isset($this->_extraScripts['calendar']))
00606 return;
00607 $style = "<link rel=\"stylesheet\" href=\"".Resource::getJsUrl()."/jscalendar/calendar-system.css\" type=\"text/css\">";
00608 $script = "<script type='text/javascript' src='".Resource::getJsUrl()."/jscalendar/calendar.js'></script>";
00609 $script .= "<script type='text/javascript' src='".Resource::getJsUrl()."/jscalendar/lang/calendar-en.js'></script>";
00610 $script .= "<script type='text/javascript' src='".Resource::getJsUrl()."/jscalendar/calendar-setup.js'></script>";
00611 $script .= "<script type='text/javascript' src='".Resource::getJsUrl()."/calendar.js'></script>";
00612 $this->appendStyles("calendar", $style, false);
00613 $this->appendScripts("calendar", $script, false);
00614 }
00615
00616
00622 public function includeColorPickerScripts()
00623 {
00624 if (isset($this->_extraScripts['colorpicker']))
00625 return;
00626 $style = "<link rel=\"stylesheet\" href=\"".Resource::getJsUrl()."/colorpicker/css/colorpicker.css\" type=\"text/css\">";
00627 $script = "<script type=\"text/javascript\" src=\"".Resource::getJsUrl()."/jquery.js\"></script>";
00628 $script .= "<script type=\"text/javascript\" src=\"".Resource::getJsUrl()."/colorpicker/js/eye.js\"></script>";
00629 $script .= "<script type=\"text/javascript\" src=\"".Resource::getJsUrl()."/colorpicker/js/utils.js\"></script>";
00630 $script .= "<script type=\"text/javascript\" src=\"".Resource::getJsUrl()."/colorpicker/js/colorpicker.js\"></script>";
00631 $this->appendStyles("colorpicker", $style, false);
00632 $this->appendScripts("colorpicker", $script, false);
00633 }
00639 public function includeRTEScripts()
00640 {
00641 if (isset($this->_extraScripts['rte']))
00642 return;
00643 $script = "<script type=\"text/javascript\" src=\"".Resource::getJsUrl()."/richtext.js\"></script>";
00644 $script .= "<script language=\"JavaScript\">initRTE('".Resource::getImageUrl()."/rte/', '../pages/rte/', '', false);</script>";
00645 $this->appendScripts("rte", $script, false);
00646 }
00647
00653 public function includeCKEditorScripts()
00654 {
00655 if (isset($this->_extraScripts['ckeditor']))
00656 return;
00657
00658 $script = "<script type=\"text/javascript\" src=\"".Resource::getJsUrl()."/ckeditor/ckeditor.js\"></script>";
00659
00660 $this->appendScripts("ckeditor", $script, false);
00661 }
00662
00668 public function includePropWindowScripts()
00669 {
00670 $this->appendScripts("scriptaculous", "scriptaculous.js");
00671 $this->appendScripts("prop_window", "window.js");
00672 $style = "<link rel=\"stylesheet\" href=\"".Resource::getJsUrl()."/window/default.css\" type=\"text/css\">";
00673
00674
00675 $this->appendStyles("prop_window", $style, false);
00676 }
00677
00683 public function includeValidatorScripts()
00684 {
00685 $this->appendScripts("yav", "yav/yav.js");
00686 $this->appendScripts("yav-cfg", "yav/yav-config.js");
00687
00688 $style = "<link rel=\"stylesheet\" href=\"".Resource::getCssUrl()."/validator.css\" type=\"text/css\">";
00689 $this->appendStyles("yav", $style, false);
00690 }
00691 }
00692 ?>