2006-11-10 16:30:01 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* eGroupWare - importexport
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package importexport
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Cornelius Weiss <nelius@cwtech.de>
|
|
|
|
* @copyright Cornelius Weiss <nelius@cwtech.de>
|
2006-11-10 16:38:31 +01:00
|
|
|
* @version $Id$
|
2006-11-10 16:30:01 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.definition.inc.php');
|
2007-06-08 00:08:38 +02:00
|
|
|
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.arrayxml.inc.php');
|
2007-06-09 17:36:30 +02:00
|
|
|
require_once(EGW_INCLUDE_ROOT. '/importexport/inc/class.import_export_helper_functions.inc.php');
|
2006-11-10 16:30:01 +01:00
|
|
|
require_once(EGW_INCLUDE_ROOT.'/etemplate/inc/class.so_sql.inc.php');
|
|
|
|
|
|
|
|
/** bo to define {im|ex}ports
|
|
|
|
*
|
|
|
|
* @todo make this class an egw_record_pool!
|
|
|
|
*/
|
|
|
|
class bodefinitions {
|
|
|
|
|
|
|
|
const _appname = 'importexport';
|
|
|
|
const _defintion_talbe = 'egw_importexport_definitions';
|
|
|
|
|
|
|
|
/**
|
2007-06-09 17:36:30 +02:00
|
|
|
* @var so_sql holds so_sql
|
2006-11-10 16:30:01 +01:00
|
|
|
*/
|
|
|
|
private $so_sql;
|
2007-06-09 17:36:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array hold definitions
|
|
|
|
*/
|
2006-11-10 16:30:01 +01:00
|
|
|
private $definitions;
|
|
|
|
|
|
|
|
public function __construct($_query=false)
|
|
|
|
{
|
|
|
|
$this->so_sql = new so_sql(self::_appname, self::_defintion_talbe );
|
|
|
|
if ($_query) {
|
|
|
|
$definitions = $this->so_sql->search($_query, true);
|
|
|
|
foreach ((array)$definitions as $definition) {
|
|
|
|
$this->definitions[] = $definition['definition_id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-08 00:08:38 +02:00
|
|
|
/**
|
2007-06-09 17:36:30 +02:00
|
|
|
* gets array of definition ids
|
|
|
|
*
|
2007-06-08 00:08:38 +02:00
|
|
|
* @return array
|
|
|
|
*/
|
2006-11-10 16:30:01 +01:00
|
|
|
public function get_definitions() {
|
|
|
|
return $this->definitions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* reads a definition from database
|
|
|
|
*
|
2007-06-08 00:08:38 +02:00
|
|
|
* @deprecated see class.definition.inc.php
|
2006-11-10 16:30:01 +01:00
|
|
|
* @param mixed &$definition
|
|
|
|
* @return bool success or not
|
|
|
|
*/
|
2007-06-08 00:08:38 +02:00
|
|
|
public function read(&$definition) {
|
2006-11-10 16:30:01 +01:00
|
|
|
if(is_int($definition)) $definition = array('definition_id' => $definition);
|
|
|
|
elseif(is_string($definition)) $definition = array('name' => $definition);
|
|
|
|
if(!$definition = $this->so_sql->read($definition)) return false;
|
|
|
|
$definition += (array)unserialize($definition['plugin_options']);
|
|
|
|
unset($definition['plugin_options']);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-06-08 00:08:38 +02:00
|
|
|
/**
|
|
|
|
* deletes a defintion
|
|
|
|
*
|
|
|
|
* @param array $keys
|
|
|
|
*/
|
|
|
|
public function delete($keys) {
|
2006-11-10 16:30:01 +01:00
|
|
|
$this->so_sql->delete(array('definition_id' => $keys));
|
2007-06-08 00:08:38 +02:00
|
|
|
// clear private cache
|
2006-11-16 12:04:09 +01:00
|
|
|
foreach ($keys as $key) {
|
|
|
|
unset($this->definitions[array_search($key,$this->definitions)]);
|
|
|
|
}
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* checkes if user if permitted to access given definition
|
|
|
|
*
|
|
|
|
* @param array $_definition
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
static public function is_permitted($_definition) {
|
|
|
|
$allowed_user = explode(',',$_definition['allowed_users']);
|
|
|
|
$this_user_id = $GLOBALS['egw_info']['user']['userid'];
|
|
|
|
$this_membership = $GLOBALS['egw']->accounts->membership($this_user_id);
|
|
|
|
$this_membership[] = array('account_id' => $this_user_id);
|
|
|
|
//echo $this_user_id;
|
|
|
|
//echo ' '.$this_membership;
|
|
|
|
foreach ((array)$this_membership as $account)
|
|
|
|
{
|
|
|
|
$this_membership_array[] = $account['account_id'];
|
|
|
|
}
|
|
|
|
$alluser = array_intersect($allowed_user,$this_membership_array);
|
|
|
|
return in_array($this_user_id,$alluser) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* exports definitions
|
|
|
|
*
|
|
|
|
* @param array $keys to export
|
|
|
|
*/
|
|
|
|
public function export($keys)
|
|
|
|
{
|
|
|
|
$export_data = array('metainfo' => array(
|
|
|
|
'type' => 'importexport definitions',
|
2006-11-16 12:04:09 +01:00
|
|
|
'charset' => $GLOBALS['egw']->translation->charset(),
|
2006-11-10 16:30:01 +01:00
|
|
|
'entries' => count($keys),
|
|
|
|
));
|
|
|
|
|
2007-06-08 00:08:38 +02:00
|
|
|
$export_data['definitions'] = array();
|
|
|
|
foreach ($keys as $definition_id) {
|
|
|
|
$definition = new definition( $definition_id );
|
|
|
|
$export_data['definitions'][$definition->name] = $definition->get_record_array();
|
2007-06-09 17:36:30 +02:00
|
|
|
$export_data['definitions'][$definition->name]['allowed_users'] =
|
|
|
|
import_export_helper_functions::account_id2name(
|
|
|
|
$export_data['definitions'][$definition->name]['allowed_users']
|
|
|
|
);
|
|
|
|
$export_data['definitions'][$definition->name]['owner'] =
|
|
|
|
import_export_helper_functions::account_id2name(
|
|
|
|
$export_data['definitions'][$definition->name]['owner']
|
|
|
|
);
|
2007-06-08 00:08:38 +02:00
|
|
|
unset($export_data['definitions'][$definition->name]['definition_id']);
|
|
|
|
unset($definition);
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
2007-06-08 00:08:38 +02:00
|
|
|
|
|
|
|
$xml = new arrayxml();
|
|
|
|
return $xml->array2xml($export_data, 'importExportDefinitions');
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
2007-06-08 00:08:38 +02:00
|
|
|
/**
|
|
|
|
* imports definitions from file
|
|
|
|
*
|
|
|
|
* @param string $import_file
|
|
|
|
* @throws Exeption
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function import( $_import_file )
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2007-06-08 00:08:38 +02:00
|
|
|
if ( !is_file( $_import_file ) ) {
|
|
|
|
throw new Exception("'$_import_file' is not a valid file" );
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = arrayxml::xml2array( file_get_contents( $_import_file ) );
|
|
|
|
|
|
|
|
$metainfo = $data['importExportDefinitions']['metainfo'];
|
|
|
|
$definitions = $data['importExportDefinitions']['definitions'];
|
|
|
|
unset ( $data );
|
2006-11-10 16:30:01 +01:00
|
|
|
|
2006-11-16 12:04:09 +01:00
|
|
|
// convert charset into internal used charset
|
2007-06-08 00:08:38 +02:00
|
|
|
$definitions = $GLOBALS['egw']->translation->convert(
|
|
|
|
$definitions,
|
|
|
|
$metainfo['charset'],
|
|
|
|
$GLOBALS['egw']->translation->charset()
|
|
|
|
);
|
2006-11-16 12:04:09 +01:00
|
|
|
|
|
|
|
// save definition(s) into internal table
|
2007-06-08 00:08:38 +02:00
|
|
|
foreach ( $definitions as $name => $definition_data )
|
2006-11-10 16:30:01 +01:00
|
|
|
{
|
2007-06-09 17:36:30 +02:00
|
|
|
// convert allowed_user
|
|
|
|
$definition_data['allowed_users'] = import_export_helper_functions::account_name2id( $definition_data['allowed_users'] );
|
|
|
|
$definition_data['owner'] = import_export_helper_functions::account_name2id( $definition_data['owner'] );
|
|
|
|
|
2007-06-08 00:08:38 +02:00
|
|
|
$definition = new definition( $definition_data['name'] );
|
|
|
|
$definition_id = $definition->get_identifier() ? $definition->get_identifier() : NULL;
|
|
|
|
|
|
|
|
$definition->set_record( $definition_data );
|
|
|
|
$definition->save( $definition_id );
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
}
|
2007-06-08 00:08:38 +02:00
|
|
|
|
2006-11-10 16:30:01 +01:00
|
|
|
}
|
|
|
|
|