status)) $this->status = $this->init_sources_status();
return $this->status;
}
function init_sources_status(){
$sgbd = $this->sgbd();
$env = $this->env();
$status = array();
try{
$sql = "SELECT * FROM #--sml_classes";
$rst = $sgbd->query($sql);
while($v_rst = $sgbd->fetch_assoc($rst)) $status[$v_rst["id"]] = $v_rst;
$sgbd->free_result($rst);
}
catch(Exception $e) { $status = false; }
return $status;
}
# ----------------------------------------------------------------------------------------
# sources
#
function init_sources_table(){
return true;
}
function sources($params){
$start = isset($params["start"]) ? $params["start"] : null;
$id_user = isset($params["id_user"]) ? $params["id_user"] : null;
$id_groupe = isset($params["id_groupe"]) ? $params["id_groupe"] : null;
$status = isset($params["status"]) ? $params["status"] : null;
$id_source = isset($params["id_source"]) ? $params["id_source"] : null;
$id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null;
$id_source_derivation = isset($params["id_source_derivation"]) ? $params["id_source_derivation"] : null;
$id_licence = isset($params["id_licence"]) ? $params["id_licence"] : null;
$order_by = isset($params["order_by"]) ? $params["order_by"] : "ordre";
$order = isset($params["order"]) ? $params["order"] : "ASC";
$sgbd = $this->sgbd();
$env = $this->env();
$ORDER_FIELD_EXISTS = false;
$ORDER_FROM_SOURCES_INFOS = !$ORDER_FIELD_EXISTS;
$sources = array("list" => array(), "total" => 0);
$COUNT_SELECT = "SELECT count(*) as n";
$SELECT = "SELECT #--sml_sources.*, #--sml_sources.id_class as `status`";
if($ORDER_FROM_SOURCES_INFOS){
if($order_by == "ordre"){
$SELECT .= ", (0 + #--sml_sources_infos.`value`) as ordre";
}
else{
$SELECT .= ", #--sml_sources_infos.`value` as ".$this->eq($order_by, false);
}
}
$FROM = "#--sml_sources";
if(isset($id_user)) $FROM .= ", #--sml_authors, #--sml_sources_authors";
elseif(isset($id_groupe)) $FROM .= ", #--sml_sources_authors";
if(isset($id_source)) $FROM .= ", #--sml_source_compositions";
elseif(isset($id_composition) && $id_composition) $FROM .= ", #--sml_source_compositions";
if(isset($id_source_derivation)) $FROM .= ", #--sml_source_derivations";
$FROM = " FROM (".$FROM.")";
if($ORDER_FROM_SOURCES_INFOS){
$FROM .=
" LEFT JOIN #--sml_sources_infos"
." ON (#--sml_sources_infos.id_source=#--sml_sources.id AND #--sml_sources_infos.`key`=".$this->eq($order_by).")";
}
$WHERE = "";
if(isset($id_user)) $WHERE .=
($WHERE ? " AND " : " WHERE ")
." #--sml_sources.id=#--sml_sources_authors.id_source"
." AND #--sml_sources_authors.id_author=#--sml_authors.id"
." AND #--sml_authors.id_user=".$this->eq($id_user)/*
." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin()*/;
if(isset($id_groupe)) $WHERE .=
($WHERE ? " AND " : " WHERE ")
." #--sml_sources.id=#--sml_sources_authors.id_source"
." AND #--sml_sources_authors.id_author=".$this->eq($id_groupe)/*
." AND #--sml_sources_authors.id_sources_access=".$this->id_groupe_status_admin()*/;
if(isset($status)) $WHERE .=
($WHERE ? " AND " : " WHERE ")
." #--sml_sources.id_class=".$this->eq($status);
if(isset($id_source)) $WHERE .=
($WHERE ? " AND " : " WHERE ")
." #--sml_sources.id=#--sml_source_compositions.id_composition"
." AND #--sml_source_compositions.id_source=".$this->eq($id_source);
elseif(isset($id_composition))
{ if($id_composition)
{ $WHERE .=
($WHERE ? " AND " : " WHERE ")
." #--sml_sources.id=#--sml_source_compositions.id_source"
." AND #--sml_source_compositions.id_composition=".$this->eq($id_composition);
}
else
{ if(($sources_ids = $this->source_compositions(array("id_composition" => ""))) !== false)
{ if($sources_ids)
{ $NOT_IN = "";
foreach($sources_ids as $in_source_id) $NOT_IN .= ($NOT_IN ? "," : "").$in_source_id;
$WHERE .= ($WHERE ? " AND " : " WHERE ")." #--sml_sources.id NOT IN(".$NOT_IN.")";
}
}
else return false;
}
}
if(isset($id_source_derivation)) $WHERE .=
($WHERE ? " AND " : " WHERE ")
." #--sml_sources.id=#--sml_source_derivations.id_source"
." AND #--sml_source_derivations.derivation=".$this->eq($this->source_xml_url($id_source_derivation));
if(isset($id_licence)) $WHERE .=
($WHERE ? " AND " : " WHERE ")
." #--sml_sources.licence=".$this->eq($id_licence);
$ORDER_BY = " ORDER BY ".$order_by." ".$order;
$LIMIT = (isset($start) && $env->config("max_list") ? " LIMIT ".$env->config("max_list")." OFFSET ".$start : "");
try{
$sql = $COUNT_SELECT.$FROM.$WHERE;
$rst = $sgbd->query($sql);
if($v_rst = $sgbd->fetch_assoc($rst)) $sources["total"] = $v_rst["n"];
$sgbd->free_result($rst);
if($sources["total"])
{ $sql = $SELECT.$FROM.$WHERE.$ORDER_BY.$LIMIT;
$rst = $sgbd->query($sql);
$OK = true;
while($v_rst = $sgbd->fetch_assoc($rst)){
if(($sources["list"][$v_rst["id"]] = $this->load_source($v_rst)) === false){
$OK = false;
break;
}
}
$sgbd->free_result($rst);
if(!$OK) return false;
}
}
catch(Exception $e) { $sources = false; }
return $sources;
}
function source($id, $load = false){
$sgbd = $this->sgbd();
try{
$sql = "SELECT #--sml_sources.*, #--sml_sources.id_class as status FROM #--sml_sources WHERE id=".$this->eq($id);
$rst = $sgbd->query($sql);
$source = array();
if($v_rst = $sgbd->fetch_assoc($rst)){
$source = $load ? $this->load_source($v_rst) : $this->get_source_from_v_rst($v_rst);
}
$sgbd->free_result($rst);
}
catch(Exception $e) { $source = false; }
return $source;
}
function get_source_from_v_rst($v_rst){
$sgbd = $this->sgbd();
$source = $this->empty_source();
foreach($v_rst as $rst_key => $rst_value) $source[$rst_key] = $rst_value;
try{
$si_sql = "SELECT * FROM #--sml_sources_infos WHERE id_source=".$this->eq($source["id"]);
$si_rst = $sgbd->query($si_sql);
while($v_si_rst = $sgbd->fetch_assoc($si_rst)){
if(!isset($source[$v_si_rst["key"]])) $source[$v_si_rst["key"]] = $v_si_rst["value"];
}
$sgbd->free_result($si_rst);
if($source["reference"]){
if(!is_array($source["reference"])){
$reference_url = $source["reference"];
$source["reference"] = $this->empty_source();
$source["reference"]["xml"]["url"] = $reference_url;
}
}
else{
if(!is_array($source["licence"])){
$source["licence"] = array(
"id" => $source["licence"]
);
}
}
}
catch(Exception $e) { $source = false; }
return $source;
}
function load_source($source){
$env = $this->env();
if(!isset($source["id"])) return false;
$source = $this->get_source_from_v_rst($source);
$source["xml"] = array
( "url" => $this->source_xml_url($source["id"]),
"content" => $this->get_source_xml($source["id"])
);
$source["documents"] = array();
if(($source["groupes"] = $this->source_groupes($source["id"])) === false) return false;
$source["image_uri"] =
( isset($source["image"]) && $source["image"] ?
$env->path("content")."uploads/".$source["image"]
: ""
);
if(($source["has_sources"] = $this->has_sources($source["id"])) === false) return false;
if(($source["has_derivations"] = $this->source_derivations(array("derivation" => $source["id"]))) === false) return false;
if(($source["derivations"] = $this->source_derivations(array("id_source" => $source["id"]))) === false) return false;
if(($source["reference"] = $this->source_reference($source)) === false) return false;
if(!$source["reference"])
{ if(($source["documents"] = $this->source_documents($source["id"])) === false) return false;
}
return $source;
}
function add_source
( $groupes,
$titre,
$status,
$licence,
$documents = array(),
$reference = array(),
$derivations = array(),
$infos = array()
)
{ $sgbd = $this->sgbd();
$source = array
( "groupes" => $groupes,
"titre" => $reference ? null : $titre,
"status" => $status,
"licence" => $reference ? null : $licence,
"reference" => $reference ? $reference : null,
"date_creation" => isset($infos["date_creation"]) ? $infos["date_creation"] : null,
"date_inscription" => isset($infos["date_inscription"]) ? $infos["date_inscription"] : date("Y-m-d")
);
try{
$sql =
"INSERT INTO #--sml_sources(id_class, reference, titre, licence, date_creation, date_inscription)"
." VALUES"
."( ".$this->eq($source["status"])
.", ".$this->eq($source["reference"] ? $source["reference"]["xml"]["url"] : null)
.", ".$this->eq($source["titre"])
.", ".$this->eq($source["licence"])
.", ".$this->eq($source["date_creation"])
.", ".$this->eq($source["date_inscription"])
.")";
$sgbd->query($sql);
$id = $sgbd->insert_id();
foreach($source["groupes"] as $id_groupe => $groupe)
{ if($groupe["id"] && $groupe["id_groupe_status"])
{ if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false;
}
else return false;
}
if(isset($infos["date_creation"])) unset($infos["date_creation"]);
if(isset($infos["date_inscription"])) unset($infos["date_inscription"]);
foreach($infos as $key => $value){
$sql =
"INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
." VALUES"
."( ".$this->eq($id)
.", ".$this->eq($key)
.", ".$this->eq($value)
.")";
$sgbd->query($sql);
}
}
catch(Exception $e) { return false; }
foreach($derivations as $source_derivation)
{ if
( ( $id_source_derivation = $this->add_source_derivation
( $id,
$source_derivation["xml"]["url"],
$source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : ""
)
) === false
)
{ return false;
}
}
if($reference)
{ if($reference["xml"]["use_edit_content"])
{ if(!$this->set_edit_reference_content($id, $reference["xml"]["content"]))
{ return false;
}
}
}
else
{ foreach($documents as $document)
{ if(!$this->add_source_document($id, $document)) return false;
}
}
if(!$this->set_source_xml($id)) return false;
return $id;
}
function set_source
( $id,
$groupes,
$titre,
$status,
$licence,
$documents = array(),
$reference = array(),
$derivations = array(),
$infos = array()
)
{ if($source = $this->source($id))
{ $sgbd = $this->sgbd();
$source = array
( "groupes" => $groupes,
"titre" => $reference ? null : $titre,
"licence" => $reference ? null : $licence,
"reference" => $reference ? $reference : null,
"date_creation" => isset($infos["date_creation"]) ? $infos["date_creation"] : null
);
try{
$sql =
"UPDATE #--sml_sources SET"
." reference=".$this->eq($source["reference"] ? $source["reference"]["xml"]["url"] : null)
.", titre=".$this->eq($source["titre"])
.", licence=".$this->eq($source["licence"])
.", date_creation=".$this->eq($source["date_creation"])
." WHERE id=".$this->eq($id);
$sgbd->query($sql);
if(!$this->del_source_groupes($id)) return false;
foreach($source["groupes"] as $id_groupe => $groupe)
{ if($groupe["id"] && $groupe["id_groupe_status"]){
if(!$this->add_source_groupe($id, $groupe["id"], $groupe["id_groupe_status"])) return false;
}
else return false;
}
$sql = "DELETE FROM #--sml_sources_infos WHERE id_source=".$this->eq($id);
$sgbd->query($sql);
if(isset($infos["date_creation"])) unset($infos["date_creation"]);
if(isset($infos["date_inscription"])) unset($infos["date_inscription"]);
foreach($infos as $key => $value)
{ $sql =
"INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
." VALUES"
."( ".$this->eq($id)
.", ".$this->eq($key)
.", ".$this->eq($value)
.")";
$sgbd->query($sql);
}
}
catch(Exception $e) { return false; }
if(!$this->del_source_derivations($id)) return false;
if(!$this->del_edit_reference_content($id)) return false;
if(!$this->del_source_documents($id)) return false;
foreach($derivations as $source_derivation)
{ if
( ( $id_source_derivation = $this->add_source_derivation
( $id,
$source_derivation["xml"]["url"],
$source_derivation["xml"]["use_edit_content"] ? $source_derivation["xml"]["content"] : ""
)
) === false
)
{ return false;
}
}
if($reference)
{ if($reference["xml"]["use_edit_content"])
{ if(!$this->set_edit_reference_content($id, $reference["xml"]["content"]))
{ return false;
}
}
}
else{
foreach($documents as $document){
if(!$this->add_source_document($id, $document)) return false;
}
}
if(!$this->set_source_xml($id)) return false;
return true;
}
return false;
}
function set_source_info($id_source, $key, $value){
$sgbd = $this->sgbd();
try{
$sql =
"SELECT id FROM #--sml_sources_infos"
." WHERE id_source=".$this->eq($id_source)
." AND `key`=".$this->eq($key);
$rst = $sgbd->query($sql);
$id = null;
if($v_rst = $sgbd->fetch_assoc($rst)) $id = $v_rst["id"];
$sgbd->free_result($rst);
if(isset($id)) $sql =
"UPDATE #--sml_sources_infos SET"
." `value`=".$this->eq($value)
." WHERE id=".$this->eq($id);
else $sql =
"INSERT INTO #--sml_sources_infos(id_source, `key`,`value`)"
." VALUES"
."( ".$this->eq($id_source)
.", ".$this->eq($key)
.", ".$this->eq($value)
.")";
$sgbd->query($sql);
if(!isset($id)) $id = $sgbd->insert_id();
}
catch(Exception $e) { return false; }
return $id;
}
function del_source($id){
$sgbd = $this->sgbd();
if(!$this->del_source_compositions(array("id_source" => $id, "id_composition" => $id))) return false;
if(!$this->del_edit_reference_content($id)) return false;
if(!$this->del_source_derivations($id)) return false;
if(!$this->del_source_xml($id)) return false;
if(!$this->del_source_documents($id)) return false;
if(!$this->del_source_groupes($id)) return false;
try{
$sql = "DELETE FROM #--sml_sources_infos WHERE id_source=".$this->eq($id);
$sgbd->query($sql);
$sql = "DELETE FROM #--sml_sources WHERE id=".$this->eq($id);
$sgbd->query($sql);
}
catch(Exception $e) { return false; }
return true;
}
# ----------------------------------------------------------------------------------------
# derivations de sources
#
function init_source_derivations()
{ $sgbd = $this->sgbd();
$rst = $sgbd->table_exists("#--sml_source_derivations");
if(isset($rst))
{ if(!$rst)
{ return
"table manquante"
."
"
."
"
."
" ."(table_prefix)source_derivations :\n" ."\n" ." id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,\n" ." id_source INT NOT NULL,\n" ." derivation VARCHAR NOT NULL\n" ."\n" .""; } } else return "impossible de chercher la table #--sml_source_derivations"; return true; } function source_derivations($params) { $sgbd = $this->sgbd(); $env = $this->env(); $derivations = array(); // sources dont "id_source" est une derivation if(isset($params["id_source"])){ try{ $sql = "SELECT *" ." FROM #--sml_source_derivations" ." WHERE #--sml_source_derivations.id_source=".$this->eq($params["id_source"]); $rst = $sgbd->query($sql); while($v_rst = $sgbd->fetch_assoc($rst)) { $derivations[$v_rst["id"]] = array(); $derivation_edit_file = $this->derivation_edit_xml_path($v_rst["id_source"], $v_rst["id"]); if(file_exists($derivation_edit_file)) { if(($derivation_edit_content = $this->get_edit_derivation_content($v_rst["id_source"], $v_rst["id"])) !== false) { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"], $derivation_edit_content)) !==false) { $derivations[$v_rst["id"]]["xml"] = array ( "url" => $v_rst["derivation"], "content" => $derivation_edit_content, "use_edit_content" => true ); } else return false; } else return false; } else { if(($derivations[$v_rst["id"]] = $this->source_xml_read($v_rst["derivation"])) !==false) { $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"]; } else $derivations[$v_rst["id"]] = $this->empty_source(); } $derivations[$v_rst["id"]]["id_source"] = $v_rst["id_source"]; } $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $derivations; } // sources qui derivent de "derivation" elseif(isset($params["derivation"])) { $source_xml_url = $params["derivation"]; if(preg_match("/^[0-9]+$/", $source_xml_url)) $source_xml_url = $this->source_xml_url($source_xml_url); try{ $sql = "SELECT #--sml_sources.*" ." FROM #--sml_sources, #--sml_source_derivations" ." WHERE #--sml_sources.id=#--sml_source_derivations.id_source" ." AND #--sml_source_derivations.derivation=".$this->eq($source_xml_url); $rst = $sgbd->query($sql); if(!isset($rst)) return false; while($v_rst = $sgbd->fetch_assoc($rst)) $derivations[$v_rst["id"]] = $v_rst; $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $derivations; } return false; } function source_derivation($id){ $sgbd = $this->sgbd(); $env = $this->env(); $derivation = array(); try{ $sql = "SELECT *" ." FROM #--sml_source_derivations" ." WHERE #--sml_source_derivations.id=".$this->eq($id); $rst = $sgbd->query($sql); if($v_rst = $sgbd->fetch_assoc($rst)) $derivation = $v_rst; $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $derivation; } function add_source_derivation($id_source, $derivation, $edit_content = "") { $sgbd = $this->sgbd(); try{ $sql = "INSERT INTO #--sml_source_derivations(id_source, derivation)" ." VALUES" ."( ".$this->eq($id_source) .", ".$this->eq($derivation) .")"; $sgbd->query($sql); $id_source_derivation = $sgbd->insert_id(); } catch(Exception $e) { return false; } if($edit_content) { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content)) { return false; } } return $id_source_derivation; } function set_source_derivation($id_source_derivation, $id_source, $derivation, $edit_content = "") { $sgbd = $this->sgbd(); try{ $sql = "UPDATE #--sml_source_derivations SET" ." id_source=".$this->eq($id_source) .", derivation=".$this->eq($derivation) ." WHERE id=".$this->eq($id_source_derivation); $sgbd->query($sql); } catch(Exception $e) { return false; } if($edit_content) { if(!$this->set_edit_derivation_content($id_source, $id_source_derivation, $edit_content)) { return false; } } return true; } function del_source_derivation($id_source_derivation) { if(($derivation = $this->source_derivation($id_source_derivation)) !== false) { if(($derivations = $this->source_derivations(array("id_source" => $derivation["id_source"]))) !== false) { $sgbd = $this->sgbd(); try{ $sql = "DELETE FROM #--sml_source_derivations WHERE id=".$this->eq($id_source_derivation); $sgbd->query($sql); } catch(Exception $e) { return false; } if(count($derivations) > 1) { return $this->del_edit_derivation_content($derivation["id_source"], $id_source_derivation); } else return $this->del_edit_derivations($derivation["id_source"]); } } return false; } function del_source_derivations($id_source) { $sgbd = $this->sgbd(); try{ $sql = "DELETE FROM #--sml_source_derivations WHERE id_source=".$this->eq($id_source); $sgbd->query($sql); } catch(Exception $e) { return false; } return $this->del_edit_derivations($id_source); } # ---------------------------------------------------------------------------------------- # references # function source_reference($source) { $reference = array(); if($source["reference"]) { if(!is_array($source["reference"])) { $source["reference"] = array ( "url" => $source["reference"], "content" => "", "use_edit_content" => false ); } $reference_edit_file = $this->reference_edit_xml_path($source["id"]); if(file_exists($reference_edit_file)) { if(($reference_edit_content = $this->get_edit_reference_content($source["id"])) !== false) { if(($reference = $this->source_xml_read($source["reference"], $reference_edit_content)) !==false) { $reference["xml"] = array ( "url" => $source["reference"]["xml"]["url"], "content" => $reference_edit_content, "use_edit_content" => true ); } else return false; } else return false; } else { if(($reference = $this->source_xml_read($source["reference"]["xml"]["url"])) ===false) { $reference = $this->empty_source(); } } } return $reference; } # ---------------------------------------------------------------------------------------- # documents # function source_documents($id_source) { $sgbd = $this->sgbd(); $documents = array(); try{ $sql = "SELECT * FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source); $rst = $sgbd->query($sql); if(!isset($rst)) return false; while($v_rst = $sgbd->fetch_assoc($rst)) $documents[$v_rst["id"]] = $v_rst; $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $documents; } function add_source_document($id_source, $document) { $sgbd = $this->sgbd(); try{ $sql = "INSERT INTO #--sml_source_documents(id_source, nom, url)" ." VALUES" ."( ".$this->eq($id_source) .", ".$this->eq($document["nom"]) .", ".$this->eq($document["url"]) .")"; $sgbd->query($sql); } catch(Exception $e) { return false; } return $sgbd->insert_id(); } function del_source_documents($id_source) { $sgbd = $this->sgbd(); try{ $sql = "DELETE FROM #--sml_source_documents WHERE id_source=".$this->eq($id_source); $sgbd->query($sql); } catch(Exception $e) { return false; } return true; } # ---------------------------------------------------------------------------------------- # compositions de sources # function source_compositions($params) { $id_source = isset($params["id_source"]) ? $params["id_source"] : null; $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null; $sgbd = $this->sgbd(); $env = $this->env(); $compositions = array(); if(isset($id_source)){ try{ $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source); $rst = $sgbd->query($sql); while($v_rst = $sgbd->fetch_assoc($rst)) { if(!isset($compositions[$v_rst["id_source"]])) $compositions[$v_rst["id_source"]] = array(); $compositions[$v_rst["id_source"]][] = $v_rst["id_composition"]; } $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $compositions; } elseif(isset($id_composition)) { if($id_composition){ try{ $sql = "SELECT * FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition); $rst = $sgbd->query($sql); while($v_rst = $sgbd->fetch_assoc($rst)) { if(!isset($compositions[$v_rst["id_composition"]])) $compositions[$v_rst["id_composition"]] = array(); $compositions[$v_rst["id_composition"]][] = $v_rst["id_source"]; } $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $compositions; } else{ try{ $sql = "SELECT DISTINCT id_source FROM #--sml_source_compositions"; $rst = $sgbd->query($sql); while($v_rst = $sgbd->fetch_assoc($rst)) $compositions[] = $v_rst["id_source"]; $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $compositions; } } return false; } function set_source_composition($id_source, $id_composition){ $sgbd = $this->sgbd(); try{ $sql = "INSERT INTO #--sml_source_compositions(id_source, id_composition) VALUES" ."( ".$this->eq($id_source) .", ".$this->eq($id_composition) .")"; $sgbd->query($sql); } catch(Exception $e) { return false; } return $this->set_source_xml($id_composition); } function del_source_compositions($params){ $res = true; $id_source = isset($params["id_source"]) ? $params["id_source"] : null; $id_composition = isset($params["id_composition"]) ? $params["id_composition"] : null; $to_delete = array(); $to_update = array(); if(isset($id_composition)) $to_update[] = $id_composition; $sgbd = $this->sgbd(); if(isset($id_source)){ try{ $sql = "SELECT * FROM #--sml_source_compositions WHERE id_source=".$this->eq($id_source); $rst = $sgbd->query($sql); while($v_rst = $sgbd->fetch_assoc($rst)) $to_update[] = $v_rst["id_composition"]; $sgbd->free_result($rst); } catch(Exception $e) { return false; } } try{ $sql = "DELETE FROM #--sml_source_compositions"; $WHERE = ""; $WHERE .= (isset($id_source) ? ($WHERE ? " OR " : " WHERE ")."id_source=".$this->eq($id_source) : ""); $WHERE .= (isset($id_composition) ? ($WHERE ? " OR " : " WHERE ")."id_composition=".$this->eq($id_composition) : ""); $sql .= $WHERE; $sgbd->query($sql); } catch(Exception $e) { return false; } foreach($to_update as $id_source_xml){ if(!$this->set_source_xml($id_source_xml)) return false; } return true; } function has_sources($id_composition) { $sgbd = $this->sgbd(); $env = $this->env(); try{ $sql = "SELECT count(*) as n FROM #--sml_source_compositions WHERE id_composition=".$this->eq($id_composition); $rst = $sgbd->query($sql); $has_sources = 0; if($v_rst = $sgbd->fetch_assoc($rst)) $has_sources = $v_rst["n"]; $sgbd->free_result($rst); } catch(Exception $e) { return false; } return $has_sources; } function source_ariane($id_source, $ariane = array()) { if(($compositions = $this->source_compositions(array("id_source" => $id_source))) !== false) { if(isset($compositions[$id_source]) && $compositions[$id_source]) { foreach($compositions[$id_source] as $id_composition) { if(($ariane = $this->source_ariane($id_composition, $ariane)) !== false) { if(($ariane[$id_composition] = $this->source($id_composition)) !== false) { } else $ariane = false; } else $ariane = false; break; } } } else $ariane = false; return $ariane; } } ?>