Add php files

This commit is contained in:
2025-05-12 15:44:39 +00:00
parent c951760058
commit 82d5804ac4
9534 changed files with 2638137 additions and 0 deletions

162
uploadAjaxFile.php Executable file
View File

@@ -0,0 +1,162 @@
<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
if(!isset($_SESSION['authenticated_user_id'])) {
die("Not a Valid Entry Point");
}
switch ($_POST['job']) {
case 'getScannerList': getScannerList(); break;
case 'justScanCheck': justScan($_POST['scanner'],$_POST['nameField'],$_POST['check'],$_POST['type']); break;
case 'justPrinterCheck': justPrinterCheck($_POST['printer'],$_POST['recid'],$_POST['check'],$_POST['type'],$_POST['module'], $_POST['pdf_opt']); break;
}
function justPrinterCheck($printer,$id,$check,$type,$module, $pdf_options){
$s=new EcmDevice();
$s->retrieve($printer);
$output = shell_exec("ping -c 1 ".$s->ip." >/dev/null && echo 'true'");
if($check=='1'){
if($output==''){
echo 'false';
return;
} else {
echo 'true';
return;
}
} else {
require_once ("modules/".$module."/createPDF.php");
$opt = explode("&", $pdf_options);
if (count($opt) > 0)
foreach ($opt as $o) {
$arg = explode("=", $o);
$_REQUEST[$arg[0]] = $arg[1];
}
$module = substr($module, 0, - 1);
$function='create'.$module.'Pdf';
$fn=$function($id, 'FILE');
//echo "lpr -P ".$s->description." /var/www/html/crm/".$fn;
$output = shell_exec("lpr -P ".$s->description." /var/www/html/crm/".$fn);
echo 'true';
return;
}
}
function justScan($id,$name,$check,$type){
$new_name=create_guid();
$s=new EcmDevice();
$s->retrieve($id);
$path = '/var/www/html/crm/upload/'.$new_name;
$return=array();
if($type==0){
$command="scanimage -d '".$s->description."' -y 297 -x 205 --format tiff > ".$path;
} else {
$command="scanimage -d '".$s->description."' -y 297 -x 210 -l 35 --batch=/var/www/html/crm/tmpscan/".$new_name."_%03d.tif --resolution 300 --format tiff";
}
$output = shell_exec("ping -c 1 ".$s->ip." >/dev/null && echo 'true'");
if($check=='1'){
if($output==''){
echo 'false';
return;
} else {
echo 'true';
return;
}
} else {
if($type==0){
$output =shell_exec($command);
$filename='upload/'.$new_name;
if (file_exists($filename)) {
$command="convert -quality 50% ".$path." /var/www/html/crm/upload/".$new_name.".jpeg";
$output =shell_exec($command);
shell_exec('rm -fr /var/www/html/crm/upload/'.$new_name);
shell_exec('mv /var/www/html/crm/upload/'.$new_name.'.jpeg /var/www/html/crm/upload/'.$new_name);
echo $new_name;
return;
} else {
echo $output;
echo 'false';
return;
}
} else {
// echo $command;
$output =shell_exec($command);
shell_exec('tiffcp /var/www/html/crm/tmpscan/'.$new_name.'_???.tif /var/www/html/crm/tmpscan/mm_'.$new_name.'.tif');
shell_exec('tiff2pdf -o /var/www/html/crm/upload/tmp_'.$new_name.' /var/www/html/crm/tmpscan/mm_'.$new_name.'.tif');
shell_exec('gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=/var/www/html/crm/upload/'.$new_name.' /var/www/html/crm/upload/tmp_'.$new_name);
shell_exec('rm -fr /var/wwww/html/crm/tmpscan/mm_'.$new_name.'*');
shell_exec('rm -fr /var/wwww/html/crm/tmpscan/'.$new_name.'*');
shell_exec('rm -fr /var/wwww/html/crm/upload/tmp_'.$new_name);
echo $new_name;
return;
}
}
// echo exec('ping 192.168.1.116');
}
function getScannerList(){
$return=array();
$a=$GLOBALS['db']->query('select id,name,description from ecmdevices where type="1"');
while($b=$GLOBALS['db']->fetchByAssoc($a)){
$return[]=$b;
}
unset($a);
unset($b);
echo json_encode($return); return;
}
global $sugar_config;
if($_POST['uploadFieldName']!=''){
$success=false;
//$upload_file = new UploadFile($prefix . $field);
foreach ($_FILES[$_POST['uploadFieldName']]['name'] as $key => $value) {
$new_name=create_guid();
$target_file=$sugar_config['upload_dir'].basename($new_name);
if(move_uploaded_file($_FILES[$_POST['uploadFieldName']]["tmp_name"][$key], $target_file)){
echo '<p id="picker_'.$new_name.'">Plik '.$_FILES[$_POST['uploadFieldName']]['name'][$key].' wgrany.
<input type="hidden" name="'.$_POST['uploadFieldName'].'_newname[]" value="'.$new_name.'"/>
<input type="hidden" name="'.$_POST['uploadFieldName'].'_orginal[]" value="'.$_FILES[$_POST['uploadFieldName']]['name'][$key].'"/>
<input type="hidden" name="'.$_POST['uploadFieldName'].'_type[]" value="'.$_FILES[$_POST['uploadFieldName']]['type'][$key].'"/>
<input class="button" type="button" value="Usuń" name="button" onclick="removeFile(\''.$new_name.'\')">
</p>';
/*
$Revision = new DocumentRevision();
//save revision.
$Revision->change_log = 'test';
$Revision->revision = 1;
$Revision->document_id = $bean->id;
$Revision->filename = $_FILES[$_POST['uploadFieldName']]['name'][$key];
$Revision->file_ext = pathinfo($_FILES[$_POST['uploadFieldName']]['name'][$key], PATHINFO_EXTENSION);
$Revision->file_mime_type = $_FILES[$_POST['uploadFieldName']]['type'][$key];
$Revision->save();
$success=true;
$bean->new_with_id = true;
*/
} else {
echo 'Plik '.$_FILES[$_POST['uploadFieldName']]['name'][$key].' nie został wgrany.<br>';
}
// echo $val2.'<br>';
}
}
if($_POST['delete']!=''){
if($_POST['record']!=''){
if(unlink($sugar_config['upload_dir'].basename($_POST['record']))){
$GLOBALS['db']->query(
"update document_revisions set deleted='1' where id='" . $_POST['record']. "'");
return '1';
} else {
return '-1';
}
}
}
?>