getName())), strtolower(convert_diacrit($b->getName())));
}
class webdav extends connecteur_out {
public function get_config_form() {
//Rien
return '';
}
public function update_config_from_form() {
return;
}
public function instantiate_source_class($source_id) {
return new webdav_source($this, $source_id, $this->msg);
}
public function process($source_id, $pmb_user_id) {
global $class_path;
global $webdav_current_user_id,$webdav_current_user_name;
$source_object = $this->instantiate_source_class($source_id);
$webdav_current_user_id = 0;
$webdav_current_user_name = "Anonymous";
switch ($source_object->config['group_tree']) {
case 'scan_request' :
$rootDir = new Sabre\PMB\ScanRequest\Tree($source_object->config);
break;
case 'music' :
$rootDir = new Sabre\PMB\Music\Tree($source_object->config);
break;
case 'standard' :
default :
$rootDir = new Sabre\PMB\Tree($source_object->config);
break;
}
$server = new Sabre\DAV\Server($rootDir);
if($source_object->config['allow_web']){
$web = new Sabre\PMB\BrowserPlugin();
$server->addPlugin($web);
}
if($source_object->config['authentication'] != "anonymous"){
$auth = new Sabre\PMB\Auth($source_object->config['authentication']);
$authPlugin = new Sabre\DAV\Auth\Plugin($auth);
// Adding the plugin to the server
$server->addPlugin($authPlugin);
}
// We're required to set the base uri, it is recommended to put your webdav server on a root of a domain
$server->setBaseUri($source_object->config['base_uri']);
// And off we go!
$server->exec();
}
}
class webdav_source extends connecteur_out_source {
public $onglets = array();
public $groups_collections = array();
public function __construct($connector, $id, $msg) {
parent::__construct($connector, $id, $msg);
$this->included_sets = isset($this->config["included_sets"]) ? $this->config["included_sets"] : array();
}
protected function get_msg_to_display($message) {
global $msg;
if (substr($message, 0, 4) == "msg:") {
if(isset($this->msg[substr($message, 4)])){
return $this->msg[substr($message, 4)];
}
}
return $message;
}
protected function parse_file_collections() {
global $base_path;
//Liste des collections possibles
if (file_exists("$base_path/admin/connecteurs/out/webdav/collections_subst.xml"))
$filename = "$base_path/admin/connecteurs/out/webdav/collections_subst.xml";
else
$filename = "$base_path/admin/connecteurs/out/webdav/collections.xml";
$xml=file_get_contents($filename);
$param=_parser_text_no_function_($xml,"COLLECTIONS");
foreach ($param['GROUPS'][0]['GROUP'] as $group) {
$group_collections = array();
if(!empty($group['COLLECTION'])){
foreach ($group['COLLECTION'] as $collection) {
$group_collections[$collection['CODE']] = $this->get_msg_to_display($collection['value']);
}
}
$this->groups_collections[$group['NAME']] = array(
'label' => $this->get_msg_to_display($group['VALUE']),
'collections' => $group_collections,
'class' => $group['CLASS']
);
}
}
public function get_groups_collections() {
if(!count($this->groups_collections)){
$this->parse_file_collections();
}
return $this->groups_collections;
}
public function get_group_collections($name) {
if(!count($this->groups_collections)){
$this->parse_file_collections();
}
return $this->groups_collections[$name]['collections'];
}
public function get_config_form() {
global $charset, $msg;
global $base_path, $class_path;
if(empty($this->config['base_uri'])){
$this->config['base_uri'] = "/";
}
if(empty($this->config['group_tree'])){
$this->config['group_tree'] = 'standard';
}
if(empty($this->config['restricted_empr_write_permission'])){
$this->config['restricted_empr_write_permission'] = array();
}
if(empty($this->config['restricted_user_write_permission'])){
$this->config['restricted_user_write_permission'] = array();
}
if(empty($this->config['metasMapper_class'])){
$this->config['metasMapper_class'] = "";
}
if(empty($this->config['allow_web'])){
$this->config['allow_web'] = 0;
}
if(empty($this->config['authentication'])){
$this->config['authentication'] = "opac";
}
if(empty($this->config['write_permission'])){
$this->config['write_permission'] = 0;
}
if(empty($this->config['upload_rep'])){
global $PMBuserid;
$query = "select deflt_upload_repertoire from users where userid = ".$PMBuserid;
$result = pmb_mysql_query($query);
if(pmb_mysql_num_rows($result)){
$this->config['upload_rep'] = pmb_mysql_result($result,0,0);
}else{
$this->config['upload_rep'] = 0;
}
}
$result = parent::get_config_form();
//Included sets
$result.= "
".htmlentities($this->msg['webdav_yes'],ENT_QUOTES,$charset)." config['allow_web'] == 1 ? "checked='checked'" : "")."/>
".htmlentities($this->msg['webdav_no'],ENT_QUOTES,$charset)." config['allow_web'] == 0 ? "checked='checked'" : "")."/>
".htmlentities($this->msg['webdav_yes'],ENT_QUOTES,$charset)." config['write_permission'] == 1 ? "checked='checked'" : "")."/>
".htmlentities($this->msg['webdav_no'],ENT_QUOTES,$charset)." config['write_permission'] == 0 ? "checked='checked'" : "")."/>
";
//groupes d'utilisateurs
$result.= "
";
$query = "SELECT grp_id, grp_name FROM users_groups ORDER BY grp_name ";
$res = pmb_mysql_query($query);
if(pmb_mysql_num_rows($res)>0){
$result .= "
";
}
$result.= "
";
$result.= "
";
//catégories de lecteurs
$requete = "SELECT id_categ_empr, libelle FROM empr_categ ORDER BY libelle ";
$res = pmb_mysql_query($requete);
if(pmb_mysql_num_rows($res)>0){
$result .= "
";
}
$result.= "
";
$result.="
";
$result.= '';
require_once($base_path.'/admin/connecteurs/out/webdav/groups/'.$this->groups_collections[$this->config['group_tree']]['class'].'.class.php');
$webdav_group = new $this->groups_collections[$this->config['group_tree']]['class']($this->config, $this->get_group_collections($this->config['group_tree']), $this->msg);
$result.= '';
$result.= $webdav_group->get_config_form();
if ($config_form_script = $webdav_group->get_config_form_script()) {
$result.='';
}
$result.='
';
$result.="
";
$query = "select id_notice_statut, gestion_libelle from notice_statut order by gestion_libelle";
$res = pmb_mysql_query($query);
if(pmb_mysql_num_rows($res)){
$result .="
";
}
$result.="
";
//Intégration de la gestion de l'interface de l'upload
//statut docunum
$result.="
";
$query = "select id_explnum_statut, gestion_libelle from explnum_statut order by gestion_libelle";
$res = pmb_mysql_query($query);
if(pmb_mysql_num_rows($res)){
$result .="
";
}
$result.="
";
global $pmb_docnum_in_database_allow,$pmb_docnum_in_directory_allow;
$result.= "";
if ($pmb_docnum_in_database_allow) {
$result .= " ";
}
if ($pmb_docnum_in_directory_allow) {
$result .= " ";
$req="select repertoire_id, repertoire_nom from upload_repertoire order by repertoire_nom";
$res = pmb_mysql_query($req);
if(pmb_mysql_num_rows($res)){
$result.="
";
}
}
if($pmb_docnum_in_directory_allow && !empty($this->config['up_place'])){
$result = str_replace('!!check_base!!','', $result);
$result = str_replace('!!check_up!!',"checked='checked'", $result);
} else if($pmb_docnum_in_database_allow) {
$result = str_replace('!!check_up!!','', $result);
$result = str_replace('!!check_base!!',"checked='checked'", $result);
}
$result .= "
";
return $result;
}
public function update_config_from_form() {
global $included_sets;
global $group_tree_elem;
global $authentication;
global $write_permission;
global $restricted_empr_write_permission,$restricted_user_write_permission;
global $default_statut;
global $base_uri;
global $id_rep;
global $up_place;
global $allow_web;
global $default_docnum_statut;
global $metasMapper_class;
global $base_path;
global $class_path;
parent::update_config_from_form();
$this->config['included_sets'] = $included_sets;
$this->config['group_tree'] = $group_tree_elem;
$this->config['authentication']= $authentication;
$this->config['write_permission']= $write_permission;
$this->config['restricted_empr_write_permission'] = $restricted_empr_write_permission;
$this->config['restricted_user_write_permission'] = $restricted_user_write_permission;
$this->config['default_statut'] = $default_statut;
$this->config['base_uri'] = $base_uri;
$this->config['upload_rep'] = $id_rep;
$this->config['up_place'] = $up_place;
$this->config['allow_web'] = $allow_web;
$this->config['default_docnum_statut'] = $default_docnum_statut;
$this->config['metasMapper_class'] = $metasMapper_class;
if ($this->config['group_tree']) {
$this->get_groups_collections();
$group_class = $this->groups_collections[$this->config['group_tree']]['class'];
require_once($base_path.'/admin/connecteurs/out/webdav/groups/'.$group_class.'.class.php');
$this->config = array_merge($this->config, $group_class::update_config_from_form());
}
return;
}
}