protected function debug($msg, $object = false) { if ($this->debug) { if ($object) { jLog::dump($object, 'jhttp debug, ' . $msg); } else { jLog::log('jhttp debug, ' . $msg); } } }
function module() { $rep = $this->getResponse('htmlfragment'); $app = $this->param('app', null, true); jLog::dump($app); $rep->tplname = $app . "~param"; $tb = jDao::get("param"); $conditions = jDao::createConditions(); if (!empty($app)) { $conditions->addCondition('app', '=', $app); } $config = $tb->findBy($conditions)->fetch(); $rep->tpl->assign('config', $config); return $rep; }
function unpackUpdate($file) { $zip = new ZipArchive(); $zip->open($file); //$zip->extractTo(jApp::appPath()); jLog::dump(jApp::appPath()); $src = jApp::appPath() . 'var/uploads/' . uniqid(); $zip->extractTo($src); //modules bos copy($src . '/project.xml', jApp::appPath() . 'project.xml'); copy($src . '/responses/myHtmlResponse.class.php', jApp::appPath() . 'responses/myHtmlResponse.class.php'); copy($src . '/responses/myJsResponse.class.php', jApp::appPath() . 'responses/myJsResponse.class.php'); copy($src . '/modules/extension/', jApp::appPath() . 'modules/extension/'); copy($src . '/modules/user/', jApp::appPath() . 'modules/user/'); copy($src . '/modules/bos/', jApp::appPath() . 'modules/bos/'); copy($src . '/modules/chat/', jApp::appPath() . 'modules/chat/'); }
/** * main method : launch the execution of the action. * * This method should be called in a entry point. * * @param jRequest $request the request object. It is required if a descendant of jCoordinator did not called setRequest before */ public function process($request = null) { jLog::log("process: start"); try { if ($request) { $this->setRequest($request); } jSession::start(); $ctrl = $this->getController($this->action); } catch (jException $e) { $config = jApp::config(); if ($config->urlengine['notfoundAct'] == '') { throw $e; } if (!jSession::isStarted()) { jSession::start(); } try { jLog::log("Exception: get notfoundact ctrl (" . $config->urlengine['notfoundAct'] . ")"); $this->action = new jSelectorAct($config->urlengine['notfoundAct']); $ctrl = $this->getController($this->action); } catch (jException $e2) { throw $e; } } jApp::pushCurrentModule($this->moduleName); if (count($this->plugins)) { $pluginparams = array(); if (isset($ctrl->pluginParams['*'])) { $pluginparams = $ctrl->pluginParams['*']; } if (isset($ctrl->pluginParams[$this->action->method])) { $pluginparams = array_merge($pluginparams, $ctrl->pluginParams[$this->action->method]); } jLog::dump($pluginparams, "process: plugin params"); foreach ($this->plugins as $name => $obj) { jLog::log("process: beforeAction on plugin {$name}"); $result = $this->plugins[$name]->beforeAction($pluginparams); if ($result) { $this->action = $result; jApp::popCurrentModule(); jApp::pushCurrentModule($result->module); jLog::log("process: beforeAction said to do internal redirect to " . $result->module . "~" . $result->resource); $this->moduleName = $result->module; $this->actionName = $result->resource; $ctrl = $this->getController($this->action); break; } } } jLog::log('process: call action'); $this->response = $ctrl->{$this->action->method}(); if ($this->response == null) { throw new jException('jelix~errors.response.missing', $this->action->toString()); } jLog::log('process: response: ' . get_class($this->response)); if (get_class($this->response) == 'jResponseRedirect') { jLog::log('process: redirection to ' . $this->response->action); } else { if (get_class($this->response) == 'jResponseRedirectUrl') { jLog::log('process: redirection to ' . $this->response->url); } } foreach ($this->plugins as $name => $obj) { jLog::log('process: beforeOutput on plugin ' . $name); $this->plugins[$name]->beforeOutput(); } jLog::log('process: call response output'); $this->response->output(); foreach ($this->plugins as $name => $obj) { jLog::log('process: afterProcess on plugin ' . $name); $this->plugins[$name]->afterProcess(); } jApp::popCurrentModule(); jSession::end(); jLog::log('process: end'); }
protected function xmlCall($method, $params) { $output_options = array("output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup", "non-ascii", "non-print"), "version" => "xmlrpc", "encoding" => "UTF-8"); if ($params == null) { $request = xmlrpc_encode_request($method, null, $output_options); } else { $request = xmlrpc_encode_request($method, $params, $output_options); $request = $this->decodeEntities($request, ENT_QUOTES, "UTF-8"); } $host = $this->_params['host'] . ":" . $this->_params['port']; $url = "/"; $httpQuery = "POST " . $url . " HTTP/1.0\r\n"; $httpQuery .= "User-Agent: xmlrpc\r\n"; $httpQuery .= "Host: " . $host . "\r\n"; $httpQuery .= "Content-Type: text/xml\r\n"; $httpQuery .= "Content-Length: " . strlen($request) . "\r\n"; $httpQuery .= "Authorization: Basic " . base64_encode($this->_params['login']) . ":" . base64_encode($this->_params['password']) . "\r\n\r\n"; $httpQuery .= $request; $sock = null; if ($this->_params['scheme'] == "https") { $prot = "ssl://"; } $sock = @fsockopen($prot . $this->_params['host'], $this->_params['port'], $errNo, $errString); if (!$sock) { jLog::log('Erreur de connexion XMLRPC'); jLog::dump($prot . $this->_params['host']); jLog::dump($this->_params['port']); jLOG::dump($httpQuery); jLOG::dump(strlen($httpQuery)); jLOG::dump($errNo); jLOG::dump($errString); throw new jException('jelix~auth.error.lds.unreachable.server'); } if (!fwrite($sock, $httpQuery, strlen($httpQuery))) { throw new jException('jelix~auth.error.lds.request.not.send'); } fflush($sock); while (!feof($sock)) { $xmlResponse .= fgets($sock); } fclose($sock); $xmlResponse = substr($xmlResponse, strpos($xmlResponse, "\r\n\r\n") + 4); $booleanFalse = "<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><boolean>0</boolean></value>\n</param>\n</params>\n</methodResponse>\n"; if ($xmlResponse == $booleanFalse) { $xmlResponse = "0"; } else { $xmlResponseTmp = xmlrpc_decode($xmlResponse, "UTF-8"); if (!$xmlResponseTmp) { $xmlResponse = iconv("ISO-8859-1", "UTF-8", $xmlResponse); $xmlResponse = xmlrpc_decode($xmlResponse, "UTF-8"); } else { $xmlResponse = $xmlResponseTmp; } } return $xmlResponse; }
/** * */ function save() { $rep = $this->getResponse('json'); if (isset($_FILES['candidats'])) { $this->success = true; //get files $file_name = 'liste_candidats_' . uniqid(); //$csv = new SplFileObject($this->saveFile($_FILES['candidats'],$file_name), 'r'); $csv = new SplFileObject($_FILES['candidats']['tmp_name'], 'r'); $csv->setFlags(SplFileObject::READ_CSV); $csv->setCsvControl(';'); $rows = array(); $i = 0; foreach ($csv as $ligne) { $rows[$i] = $ligne; $i++; } // get header ( colonnes) : fields $indexMatricule = array_search('matricule', $rows[0]); jLog::dump($indexMatricule); $indexDdn = array_search('ddn', $rows[0]); $indexLn = array_search('ln', $rows[0]); $indexConcour = array_search('concour', $rows[0]); $indexCodebarre = array_search('codebarre', $rows[0]); $indexNom = array_search('nom', $rows[0]); $indexPrenom = array_search('prenom', $rows[0]); $indexDatevisite = array_search('datevisite', $rows[0]); // instanciation de la factory $tb = jDao::get("candidat"); $cnx = jDb::getConnection(); $i = 0; set_time_limit(60 * 60); foreach ($csv as $ligne) { if ($i > 0) { try { $cnx->beginTransaction(); //i start la transaction $record = jDao::createRecord("candidat"); // on remplit le record $record->matricule = $ligne[$indexMatricule]; $record->ddn = $ligne[$indexDdn]; $record->ln = $ligne[$indexLn]; $record->concour = $ligne[$indexConcour]; $record->codedarre = $ligne[$indexCodebarre]; $record->nom = $ligne[$indexNom]; $record->prenom = $ligne[$indexPrenom]; $record->datevisite = $ligne[$indexDatevisite]; // on le sauvegarde dans la base $tb->insert($record); $cnx->commit(); } catch (Exception $e) { $cnx->rollback(); $this->msg = "Des doublons ont été detectés dans le fichier source et ignorés lors de l'operation"; } } $i++; } } $rep->data = array('success' => $this->success, 'msg' => $this->msg); return $rep; }
/** * call an xmlrpc call for a method * via the xmlrpc server in python (lmc-agent) * @param string $method name of the method * @param array $params array with param */ protected function xmlCall($method, $params) { $output_options = array("output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup", "non-ascii", "non-print"), "version" => "xmlrpc", "encoding" => "UTF-8"); //$output_options = array( "output_type" => "xml", "verbosity" => "pretty", "escaping" => array("markup", "non-ascii", "non-print"), "version" => "xmlrpc", "encoding" => "iso-8859-1" ); if ($params == null) { $request = xmlrpc_encode_request($method, null, $output_options); } else { $request = xmlrpc_encode_request($method, $params, $output_options); $request = $this->decodeEntities($request, ENT_QUOTES, "UTF-8"); } $host = $this->_params['host'] . ":" . $this->_params['port']; $url = "/"; $httpQuery = "POST " . $url . " HTTP/1.0\r\n"; $httpQuery .= "User-Agent: xmlrpc\r\n"; $httpQuery .= "Host: " . $host . "\r\n"; $httpQuery .= "Content-Type: text/xml\r\n"; $httpQuery .= "Content-Length: " . strlen($request) . "\r\n"; $httpQuery .= "Authorization: Basic " . base64_encode($this->_params['login']) . ":" . base64_encode($this->_params['password']) . "\r\n\r\n"; $httpQuery .= $request; $sock = null; // if crypted connexion if ($this->_params['scheme'] == "https") { $prot = "ssl://"; } $sock = @fsockopen($prot . $this->_params['host'], $this->_params['port'], $errNo, $errString); if (!$sock) { jLog::log('Erreur de connexion XMLRPC'); jLog::dump($prot . $this->_params['host']); jLog::dump($this->_params['port']); jLOG::dump($httpQuery); jLOG::dump(strlen($httpQuery)); jLOG::dump($errNo); jLOG::dump($errString); throw new jException('jelix~auth.error.lds.unreachable.server'); } if (!fwrite($sock, $httpQuery, strlen($httpQuery))) { throw new jException('jelix~auth.error.lds.request.not.send'); } fflush($sock); // We get the response from the server while (!feof($sock)) { $xmlResponse .= fgets($sock); } // Closing the connection fclose($sock); $xmlResponse = substr($xmlResponse, strpos($xmlResponse, "\r\n\r\n") + 4); /* To decode the XML into PHP, we use the (finaly a short function) xmlrpc_decode function. And that should've done the trick. We now have what ever the server function made in our $xmlResponse variable. Test if the XMLRPC result is a boolean value set to False. If it is the case, xmlrpc_decode will return an empty string. So we need to test this special case. */ $booleanFalse = "<?xml version='1.0'?>\n<methodResponse>\n<params>\n<param>\n<value><boolean>0</boolean></value>\n</param>\n</params>\n</methodResponse>\n"; if ($xmlResponse == $booleanFalse) { $xmlResponse = "0"; } else { $xmlResponseTmp = xmlrpc_decode($xmlResponse, "UTF-8"); //if we cannot decode in UTF-8 if (!$xmlResponseTmp) { //conversion in UTF-8 $xmlResponse = iconv("ISO-8859-1", "UTF-8", $xmlResponse); $xmlResponse = xmlrpc_decode($xmlResponse, "UTF-8"); } else { $xmlResponse = $xmlResponseTmp; } } return $xmlResponse; }