109 lines
3.7 KiB
PHP
109 lines
3.7 KiB
PHP
|
|
<?php
|
||
|
|
if (! defined('sugarEntry') || ! sugarEntry)
|
||
|
|
die('Not A Valid Entry Point');
|
||
|
|
if (! isset($_REQUEST['uid']))
|
||
|
|
die('Nie wybrano kontrahentów');
|
||
|
|
|
||
|
|
$users = array();
|
||
|
|
$accounts = explode(",", $_REQUEST['uid']);
|
||
|
|
$account_list = array();
|
||
|
|
$error = '';
|
||
|
|
$db = $GLOBALS['db'];
|
||
|
|
global $sugar_config, $current_user;
|
||
|
|
|
||
|
|
$users = array(
|
||
|
|
'preDb_577bab27048e83121574ddb97f22be59' => array(
|
||
|
|
'name' => 'E5 Polska sp. z o.o.',
|
||
|
|
'dbasename' => 'preDb_577bab27048e83121574ddb97f22be59'
|
||
|
|
),
|
||
|
|
'preDb_5b474e6d65c1f57c0b93064febee44c7' => array(
|
||
|
|
'name' => 'Klanad sp. z o.o.',
|
||
|
|
'dbasename' => 'preDb_5b474e6d65c1f57c0b93064febee44c7'
|
||
|
|
),
|
||
|
|
'preDb_a8fb05ea688ef8d7d0385b1e535e9dba' => array(
|
||
|
|
'name' => 'BDG Maria Daniszewska',
|
||
|
|
'dbasename' => 'preDb_a8fb05ea688ef8d7d0385b1e535e9dba'
|
||
|
|
),
|
||
|
|
'preDb_b6959b21151eecc7295367a46fdaf586' => array(
|
||
|
|
'name' => 'PPH Tektor s.c. A.J.J. Zjawiony',
|
||
|
|
'dbasename'=>'preDb_b6959b21151eecc7295367a46fdaf586'
|
||
|
|
),
|
||
|
|
'saassystem' => array(
|
||
|
|
'name' => 'SaaS Systems',
|
||
|
|
'dbasename'=>'saassystem'
|
||
|
|
)
|
||
|
|
);
|
||
|
|
|
||
|
|
foreach ($accounts as $account) {
|
||
|
|
$ac = new EcmProduct();
|
||
|
|
$ac->retrieve($account);
|
||
|
|
if ($ac->id == '')
|
||
|
|
continue;
|
||
|
|
$addTmp = array();
|
||
|
|
$addTmp['name'] = $ac->name;
|
||
|
|
$addTmp['id'] = $ac->id;
|
||
|
|
$account_list[] = $addTmp;
|
||
|
|
}
|
||
|
|
|
||
|
|
$added='';
|
||
|
|
if (isset($_POST['submit'])) {
|
||
|
|
if (count($_POST['users']) > 0) {
|
||
|
|
foreach ($_POST['users'] as $user) {
|
||
|
|
if ($user != '' && $users[$user]['dbasename']==$user) {
|
||
|
|
foreach ($account_list as $key => $val) {
|
||
|
|
if ($val['id'] != '') {
|
||
|
|
$zap = $db->query(
|
||
|
|
"select * from ecmproducts where id='" . $val['id'] .
|
||
|
|
"'");
|
||
|
|
$dane = $db->fetchByAssoc($zap);
|
||
|
|
$toinst = array();
|
||
|
|
$name=$dane['name'];
|
||
|
|
$id=$dane['id'];
|
||
|
|
foreach ($dane as $klucz => $wartosc) {
|
||
|
|
$toinst[] = $wartosc;
|
||
|
|
}
|
||
|
|
$insert = "insert into ecmproducts values ('" .
|
||
|
|
implode("','", $toinst) . "')";
|
||
|
|
|
||
|
|
$link = mysql_connect(
|
||
|
|
$sugar_config['dbconfig']['db_host_name'],
|
||
|
|
$sugar_config['dbconfig']['db_user_name'],
|
||
|
|
$sugar_config['dbconfig']['db_password']);
|
||
|
|
mysql_select_db($user,
|
||
|
|
$link);
|
||
|
|
$res2=mysql_query('select id from ecmproducts where id="'.$id.'"',$link);
|
||
|
|
|
||
|
|
if(!(mysql_num_rows($res2)>0)){
|
||
|
|
$added=1;
|
||
|
|
$res = mysql_query($insert, $link);
|
||
|
|
|
||
|
|
} else {
|
||
|
|
echo "<span style='color:red'>Produkt ".$dane['name'].' istnieje już w firmie '.$users[$user]['name'].'</span><br>';
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
mysql_close($link);
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$error = 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
$ss = new Sugar_Smarty();
|
||
|
|
$ss->assign('uid', $_REQUEST['uid']);
|
||
|
|
$ss->assign('body', $_REQUEST['body']);
|
||
|
|
$ss->assign('error', $error);
|
||
|
|
$ss->assign('success', $success);
|
||
|
|
$ss->assign('added', $added);
|
||
|
|
$ss->assign('users', $users);
|
||
|
|
$ss->assign('account_list', $account_list);
|
||
|
|
|
||
|
|
$content = $ss->fetch('modules/EcmProducts/tpls/share.tpl');
|
||
|
|
|
||
|
|
echo $content;
|
||
|
|
|