X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=WEB-INF%2Flib%2FttFileHelper.class.php;h=61dd6028591a8c2edeabdb364f95667b26b6cd1e;hb=817c14c6c2098d85ef912fb95898c857bf533b4f;hp=997634fea12e8c86f3c1de17a2e492a00701604f;hpb=70e77a95ac584db9d220b8f6d791baa0de084734;p=timetracker.git diff --git a/WEB-INF/lib/ttFileHelper.class.php b/WEB-INF/lib/ttFileHelper.class.php index 997634fe..61dd6028 100644 --- a/WEB-INF/lib/ttFileHelper.class.php +++ b/WEB-INF/lib/ttFileHelper.class.php @@ -79,7 +79,7 @@ class ttFileHelper { // Set the url, number of POST vars, POST data. curl_setopt($ch, CURLOPT_URL, $this->register_uri); - curl_setopt($ch, CURLOPT_POST, count($fields)); + curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -152,7 +152,7 @@ class ttFileHelper { // Set the url, number of POST vars, POST data. curl_setopt($ch, CURLOPT_URL, $this->putfile_uri); - curl_setopt($ch, CURLOPT_POST, count($fields)); + curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -230,7 +230,7 @@ class ttFileHelper { // Set the url, number of POST vars, POST data. curl_setopt($ch, CURLOPT_URL, $this->deletefile_uri); - curl_setopt($ch, CURLOPT_POST, count($fields)); + curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -275,10 +275,11 @@ class ttFileHelper { } // deleteEntityFiles - deletes all files associated with an entity. - // TODO: decide whether deleteGroupFiles and deleteOrgFiles should be - // separate functions. function deleteEntityFiles($entity_id, $entity_type) { + if (!$this->entityHasFiles($entity_id, $entity_type)) + return true; // No files to delete. + global $i18n; global $user; $mdb2 = getConnection(); @@ -304,7 +305,7 @@ class ttFileHelper { // Set the url, number of POST vars, POST data. curl_setopt($ch, CURLOPT_URL, $this->deletefiles_uri); - curl_setopt($ch, CURLOPT_POST, count($fields)); + curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -351,6 +352,21 @@ class ttFileHelper { return true; } + // entityHasFiles determines if an entity has any files referenced in database. + private function entityHasFiles($entity_id, $entity_type) { + global $user; + $mdb2 = getConnection(); + + $group_id = $user->getGroup(); + $org_id = $user->org_id; + + $sql = "select id from tt_files where org_id = $org_id and group_id = $group_id". + " and entity_type = ".$mdb2->quote($entity_type)." and entity_id = $entity_id limit 1"; + $res = $mdb2->query($sql); + $val = $res->fetchRow(); + return $val['id'] > 0; + } + // getOrgKey obtains organization key from the database. private function getOrgKey() { global $user; @@ -466,7 +482,7 @@ class ttFileHelper { // Set the url, number of POST vars, POST data. curl_setopt($ch, CURLOPT_URL, $this->getfile_uri); - curl_setopt($ch, CURLOPT_POST, count($fields)); + curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);