function desktop_hash($username,$password)
{
return md5("$username$password");
}
/**
* desktop_addnote
* @example desktop_addnote($note,$taskid);
*/
function desktop_addnote($note,$newtaskid)
{
$insnotesql = " insert into tblnote
(
taskid
, notecreatedby
, notecreatedip
, notetext
, noteissystem
)
values (
'".$newtaskid."'
, ".loginid()."
, '$_SERVER[REMOTE_ADDR]'
, '".db_col($note)."'
, 1
)";
db_exec($insnotesql,1);
if(!loginid())
cache_kickvalue('headernavigation_offernotecount');
//d("tblnote",$insnotesql);
}
function parsefullfilename($fullfilename)
{
$count = 1;
$pfile = $fullfilename;
$dochash = list_first($pfile,"-");
$todelete = $dochash."-";
$pfile = str_replace($todelete,"",$pfile,$count);
$number = list_first($pfile,"-");
$todelete = $number."-";
$pfile = str_replace($todelete,"",$pfile,$count);
// web proof file name
$pfile = websafe_filename ($pfile);
d (__line__."filename",$filename);
$userfilename = $pfile;
$title = list_first($userfilename,"---");
$filenamearray = array();
$filenamearray[dochash] = $dochash;
$filenamearray[number] = $number;
$filenamearray[filename] = $userfilename;
$filenamearray[title] = list_first( $title ,".");
return($filenamearray);
}
function process_document($fullfilename,$taskid=0)
{
d(post,$_POST);
d(get,$_GET);
//d (fullfiename,$fullfilename);
$fn = parsefullfilename($fullfilename);
//d(fn,$fn);
$title = $fn[title];
if($_POST[title])
$title = $_POST[title];
$fname = $fn[filename];
if ($_POST[rioprintedbidrequestfile])
$fname = pg_escape_string(trim($_POST[rioprintedbidrequestfile]));
$fname = websafe_filename($fname);
if($_POST[submittype][newclienttask])
{
$columnname = "clienttaskid";
$sel_id = $taskid;
$description = db_col($_POST[clienttaskdescription],tick);
}
if($_POST[submittype][newtask])
{
$columnname = "taskid";
$sel_id = $taskid;
$description = db_col($_POST[taskdescription],tick);
}
if($_POST[submittype][propertydocument])
{
$columnname = "propertyid";
$sel_id = $_POST[propertyid];
$description = db_col($_POST[description],tick);
}
// clientcompany
if($_POST[submittype][clientcompanypropertydocument])
{
$columnname = "clientcompanypropertyid";
$sel_id = $_POST[clientcompanypropertyid];
$description = db_col($_POST[description],tick);
}
if($_POST[documentpublic] == "public")
$public = 1;
else
$public = 0;
if($_POST[documenttypeid])
$documenttypeid = $_POST[documenttypeid];
else
$documenttypeid = "";
$sql = "select nextval('tbldocument_documentid_seq') as documentid";
$next = db_first($sql);
$maxdocid = $next[documentid];
$sql = "insert into tbldocument
( documentid
, documenttitle
, documentname
, $columnname
, documentdescription
, documentdateloaded
, documentpublic
, documentloadedby
, documenttypeid
, documentgroup
)
values ( $maxdocid
, ".db_col(substr($title,0,100),tick)."
, '".db_col($fname)."'
, $sel_id
, $description
, now()
, $public
, ".loginid()."
, ".db_number($documenttypeid)."
, ".($_POST[documentgroup]?"'".pg_escape_string($_POST[documentgroup])."'":"null")."
)";
db_exec($sql,1);
//d(sql,$sql);
//d(POST,$_POST);
//$sql = "select max(documentid) as docid from tbldocument";
//$arr = db_query($sql);
//$maxdocid = $arr[0][docid];
$dirname = getrelativedocumentdir($maxdocid) ;
$pathname = "$_SERVER[DOCUMENT_ROOT]/document$dirname";
//d(pathname,$pathname);
if (!is_dir($pathname)) // if directory does not exists make one
if(!mkdir_wrapper($pathname))
{
echo "
Server Configuration Issue: could not create directory : $dirname";
exit_wrapper();
}
$docfile = $pathname.$fname;
$tempname = UPLOAD_DIR.$fullfilename;
//d("Attempting to move $tempname to $docfile");
if(file_exists($tempname))
{
if (!copy($tempname, $docfile))
{
echo "
Server Configuration Issue: Could not write the file to the directory: $dirname$fname";
exit_wrapper();
}
}
else
{
echo "
The file $fname no longer exists in the uploaded directory.";
exit_wrapper();
}
if(file_exists($docfile))
unlink($tempname);
else
{
echo "
Server Configuration Issue: Could not write file $fname to directory $dirname";
exit_wrapper();
}
$sql = "insert into tbldesktoplog
( desktoplogfullfilename,
desktoploguserfilename,
desktoplogtimestamp,
documentid)
values ( '".db_col($fullfilename)."',
'".db_col($fname)."',
now(),
$maxdocid)";
db_exec($sql,1);
//The following code was added to try and reduce sql time and the possiblity of update_documents_uploaded causing duplicate keys
//because it can be ran for desktop for the whole company and in property_viewedit for property in the same company at the same time. MAC
if($_POST['submittype']['propertydocument'] && db_number($_POST['propertyid']))
update_documents_uploaded_property($_POST['propertyid']);
else
update_documents_uploaded();
return;
}