get_parms( "sbas_id" , "period" , 'status0' , 'coll0' , 'status1' , 'coll1' ); $dom = new DOMDocument(); $dom->preserveWhiteSpace = false; $dom->formatOutput = true; if ($dom->loadXML($oldxml)) { $xmlchanged = false; // foreach($parm2 as $pname=>$pvalue) foreach (array( "str:sbas_id", "str:period", 'str:status0', 'str:coll0', 'str:status1', 'str:coll1', ) as $pname) { $ptype = substr($pname, 0, 3); $pname = substr($pname, 4); $pvalue = $parm2[$pname]; if ($ns = $dom->getElementsByTagName($pname)->item(0)) { // le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu) while (($n = $ns->firstChild)) $ns->removeChild($n); } else { // le champ n'existait pas dans le xml, on le cree $dom->documentElement->appendChild($dom->createTextNode("\t")); $ns = $dom->documentElement->appendChild($dom->createElement($pname)); $dom->documentElement->appendChild($dom->createTextNode("\n")); } // on fixe sa valeur switch ($ptype) { case "str": $ns->appendChild($dom->createTextNode($pvalue)); break; case "boo": $ns->appendChild($dom->createTextNode($pvalue ? '1' : '0')); break; } $xmlchanged = true; } } return($dom->saveXML()); } public function xml2graphic($xml, $form) { if (($sxml = simplexml_load_string($xml))) // in fact XML IS always valid here... { // ... but we could check for safe values if ((int) ($sxml->period) < 1) $sxml->period = 1; elseif ((int) ($sxml->period) > 1440) // 1 jour $sxml->period = 1440; if ((string) ($sxml->delay) == '') $sxml->delay = 0; ?> get_session(); $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); ob_start(); ?>
 :   

 : 

Collection :   ====>  
Status :

cmd
status_origine = (string) $sx_task_settings->status0; $this->status_destination = (string) $sx_task_settings->status1; $this->coll_origine = (int) $sx_task_settings->coll0; $this->coll_destination = (int) $sx_task_settings->coll1; parent::load_settings($sx_task_settings); $this->mono_sbas_id = (int) $sx_task_settings->sbas_id; // in minutes $this->period = (int) $sx_task_settings->period * 60; if ($this->period <= 0 || $this->period >= 24 * 60) $this->period = 60; return $this; } protected function retrieve_sbas_content(databox $databox) { static $firstCall = true; $connbas = $databox->get_connection(); $sql_s = $sql_w = ''; $sql_parms = array(); if($this->coll_origine != '') { $sql_w .= ($sql_w?' AND ':'') .'(coll_id=:coll_org)'; $sql_parms[':coll_org'] = $this->coll_origine; } if($this->status_origine != '') { $x = explode('_', $this->status_origine); if (count($x) !== 2) throw new Exception('Error in settings for status origine'); $sql_w .= ($sql_w?' AND ':'') .'((status >> :stat_org_n & 1) = :stat_org_v)'; $sql_parms[':stat_org_n'] = $x[0]; $sql_parms[':stat_org_v'] = $x[1]; } if($this->coll_destination != '') { $sql_s .= ($sql_s?', ':'') .'coll_id=:coll_dst'; $sql_parms[':coll_dst'] = $this->coll_destination; } if($this->status_destination != '') { $x = explode('_', $this->status_destination); if (count($x) !== 2) throw new Exception('Error in settings for status destination'); $sql_s .= ($sql_s?', ':''); if((int)$x[1] === 0) $sql_s .= 'status = status &~(1 << :stat_dst)'; else $sql_s .= 'status = status |(1 << :stat_dst)'; $sql_parms[':stat_dst'] = (int)$x[0]; } if($sql_w && $sql_s) { $sql = 'UPDATE record SET ' . $sql_s . ' WHERE ' . $sql_w; $stmt = $connbas->prepare($sql); $stmt->execute($sql_parms); if($firstCall || $stmt->rowCount() != 0) { $this->log(sprintf(("SQL=%s\n (parms=%s)\n - %s changes"), str_replace(array("\r\n","\n","\r", "\t"), " ", $sql) , str_replace(array("\r\n","\n","\r","\t"), " ", var_export($sql_parms, true)) , $stmt->rowCount())); $firstCall = false; } $stmt->closeCursor(); } return array(); } protected function process_one_content(databox $databox, Array $row) { return $this; } protected function flush_records_sbas() { return $this; } protected function post_process_one_content(databox $databox, Array $row) { return $this; } public function facility() { $request = http_request::getInstance(); $appbox = appbox::get_instance(\bootstrap::getCore()); $session = $appbox->get_session(); $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); $parm = $request->get_parms("bid"); phrasea::headers(200, true, 'text/json', 'UTF-8', false); $ret = new DOMDocument("1.0", "UTF-8"); $ret->standalone = true; $ret->preserveWhiteSpace = false; $retjs = array('result'=>NULL, 'date_fields'=>array(), 'status_bits'=>array(), 'collections'=>array() ); $element = $ret->createElement('result'); $root = $ret->appendChild($element); $root->appendChild($ret->createCDATASection(var_export($parm, true))); $dfields = $root->appendChild($ret->createElement("date_fields")); $statbits = $root->appendChild($ret->createElement("status_bits")); $coll = $root->appendChild($ret->createElement("collections")); $sbas_id = (int)$parm['bid']; try { $databox = databox::get_instance($sbas_id); foreach ($databox->get_meta_structure() as $meta) { if ($meta->get_type() !== 'date') continue; $dfields->appendChild($ret->createElement("field")) ->appendChild($ret->createTextNode($meta->get_name())); $retjs['date_fields'][] = $meta->get_name(); } $status = $databox->get_statusbits(); foreach ($status as $n => $s) { $node = $statbits->appendChild($ret->createElement("bit")); $node->setAttribute('n', $n); $node->setAttribute('value', '0'); $node->setAttribute('label', $s['labeloff']); $node->appendChild($ret->createTextNode($s['labeloff'])); $node = $statbits->appendChild($ret->createElement("bit")); $node->setAttribute('n', $n); $node->setAttribute('value', '1'); $node->setAttribute('label', $s['labelon']); $node->appendChild($ret->createTextNode($s['labelon'])); $retjs['status_bits'][] = array( 'n'=>$n, 'value'=>0, 'label'=>$s['labeloff'] ? $s['labeloff'] : 'non '.$s['name'] ); $retjs['status_bits'][] = array( 'n'=>$n, 'value'=>1, 'label'=>$s['labelon'] ? $s['labelon'] : $s['name'] ); } $base_ids = $user->ACL()->get_granted_base(array(), array($sbas_id)); foreach ($base_ids as $base_id=>$collection) { $node = $coll->appendChild($ret->createElement("collection")); $node->setAttribute('id', $collection->get_coll_id()); $node->appendChild($ret->createTextNode($collection->get_name())); $retjs['collections'][] = array('id'=>(string)($collection->get_coll_id()), 'name'=>$collection->get_name()); } } catch (Exception $e) { } return p4string::jsonencode($retjs); } }