Mercurial > hg > fapweb
comparison msite.inc.php @ 1104:0a2117349f46
s/true/TRUE/g; s/false/FALSE/g;
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 14 May 2019 14:45:36 +0300 |
parents | 95b74632cfe2 |
children | 51f24cb35fc8 |
comparison
equal
deleted
inserted
replaced
1103:1fe7df7c77fb | 1104:0a2117349f46 |
---|---|
385 { | 385 { |
386 global $displayVars, $displayVarsChanged; | 386 global $displayVars, $displayVarsChanged; |
387 if (isset($displayVars[$name])) | 387 if (isset($displayVars[$name])) |
388 { | 388 { |
389 $displayVars[$name] = $value; | 389 $displayVars[$name] = $value; |
390 $displayVarsChanged[$name] = true; | 390 $displayVarsChanged[$name] = TRUE; |
391 } | 391 } |
392 else | 392 else |
393 die("No display var for '".$name."'.\n"); | 393 die("No display var for '".$name."'.\n"); |
394 } | 394 } |
395 | 395 |
656 $res = FALSE; | 656 $res = FALSE; |
657 } | 657 } |
658 else | 658 else |
659 if (strlen($email) > 0) | 659 if (strlen($email) > 0) |
660 { | 660 { |
661 if ($id !== false) | 661 if ($id !== FALSE) |
662 // By another ID, if we are updating an entry | 662 // By another ID, if we are updating an entry |
663 $sql = stPrepareSQL("SELECT * FROM attendees WHERE id<>%d AND email=%s", $id, $email); | 663 $sql = stPrepareSQL("SELECT * FROM attendees WHERE id<>%d AND email=%s", $id, $email); |
664 else | 664 else |
665 // Or just exists, if adding | 665 // Or just exists, if adding |
666 $sql = stPrepareSQL("SELECT * FROM attendees WHERE email=%s", $email); | 666 $sql = stPrepareSQL("SELECT * FROM attendees WHERE email=%s", $email); |
667 | 667 |
668 if (($data = stFetchSQL($sql)) !== false) | 668 if (($data = stFetchSQL($sql)) !== FALSE) |
669 { | 669 { |
670 stError("Someone with the same e-mail address is already registered."); | 670 stError("Someone with the same e-mail address is already registered."); |
671 $res = FALSE; | 671 $res = FALSE; |
672 } | 672 } |
673 } | 673 } |
674 | 674 |
675 // Check if another user already exists | 675 // Check if another user already exists |
676 if ($chk >= 2) | 676 if ($chk >= 2) |
677 { | 677 { |
678 if ($id !== false) | 678 if ($id !== FALSE) |
679 // By another ID, if we are updating an entry | 679 // By another ID, if we are updating an entry |
680 $sql = stPrepareSQL("SELECT * FROM attendees WHERE id<>%d AND name=%s AND groups=%s", $id, $name, $groups); | 680 $sql = stPrepareSQL("SELECT * FROM attendees WHERE id<>%d AND name=%s AND groups=%s", $id, $name, $groups); |
681 else | 681 else |
682 // Or just exists, if adding | 682 // Or just exists, if adding |
683 $sql = stPrepareSQL("SELECT * FROM attendees WHERE name=%s AND groups=%s", $name, $groups); | 683 $sql = stPrepareSQL("SELECT * FROM attendees WHERE name=%s AND groups=%s", $name, $groups); |
684 | 684 |
685 if (($data = stFetchSQL($sql)) !== false) | 685 if (($data = stFetchSQL($sql)) !== FALSE) |
686 { | 686 { |
687 stError("Someone with the same name and groups is already registered."); | 687 stError("Someone with the same name and groups is already registered."); |
688 $res = FALSE; | 688 $res = FALSE; |
689 } | 689 } |
690 } | 690 } |
768 function stGetCompoResults($flags) | 768 function stGetCompoResults($flags) |
769 { | 769 { |
770 $userKeyMode = stGetSetting("userKeyMode"); | 770 $userKeyMode = stGetSetting("userKeyMode"); |
771 $out = array(); | 771 $out = array(); |
772 $sql = "SELECT * FROM compos ".(($flags & RFLAG_HIDDEN_COMPOS) ? "" : "WHERE visible<>0 ")."ORDER BY name DESC"; | 772 $sql = "SELECT * FROM compos ".(($flags & RFLAG_HIDDEN_COMPOS) ? "" : "WHERE visible<>0 ")."ORDER BY name DESC"; |
773 if (($res = stExecSQL($sql)) === false) | 773 if (($res = stExecSQL($sql)) === FALSE) |
774 return $out; | 774 return $out; |
775 | 775 |
776 // For each compo that has been set visible | 776 // For each compo that has been set visible |
777 foreach ($res as $compo) | 777 foreach ($res as $compo) |
778 { | 778 { |
969 | 969 |
970 function stGetPreviewFileData($compo, $entry, &$pdata) | 970 function stGetPreviewFileData($compo, $entry, &$pdata) |
971 { | 971 { |
972 global $fileTypeData; | 972 global $fileTypeData; |
973 | 973 |
974 if ($compo === false || $entry === false) | 974 if ($compo === FALSE || $entry === FALSE) |
975 return FALSE; | 975 return FALSE; |
976 | 976 |
977 $previewPath = stGetSetting("previewPath"); | 977 $previewPath = stGetSetting("previewPath"); |
978 $previewURL = stGetSetting("previewURL"); | 978 $previewURL = stGetSetting("previewURL"); |
979 $pdata = array( | 979 $pdata = array( |
982 "exists" => 0, | 982 "exists" => 0, |
983 "files" => array(), | 983 "files" => array(), |
984 ); | 984 ); |
985 | 985 |
986 if ($entry["preview_id"] != 0 && | 986 if ($entry["preview_id"] != 0 && |
987 ($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["preview_id"])) !== false) | 987 ($efile = stFetchSQL("SELECT * FROM files WHERE deleted=0 AND id=".$entry["preview_id"])) !== FALSE) |
988 { | 988 { |
989 $pdata["file"] = $efile; | 989 $pdata["file"] = $efile; |
990 if (isset($fileTypeData[$efile["filetype"]]["type"])) | 990 if (isset($fileTypeData[$efile["filetype"]]["type"])) |
991 $pdata["type"] = $fileTypeData[$efile["filetype"]]["type"]; | 991 $pdata["type"] = $fileTypeData[$efile["filetype"]]["type"]; |
992 } | 992 } |
993 else | 993 else |
994 if ($entry["file_id"] == 0) | 994 if ($entry["file_id"] == 0) |
995 $pdata["valid"] = $efile = false; | 995 $pdata["valid"] = $efile = FALSE; |
996 | 996 |
997 switch ($pdata["type"]) | 997 switch ($pdata["type"]) |
998 { | 998 { |
999 case EFILE_IMAGE: | 999 case EFILE_IMAGE: |
1000 $pdata["files"]["image"] = stGetEntryPreviewFile( | 1000 $pdata["files"]["image"] = stGetEntryPreviewFile( |
1088 function stProbeFileInfo($filename, $silent = FALSE) | 1088 function stProbeFileInfo($filename, $silent = FALSE) |
1089 { | 1089 { |
1090 global $fileTypeData; | 1090 global $fileTypeData; |
1091 | 1091 |
1092 // Get file magic info | 1092 // Get file magic info |
1093 if (($finfo = finfo_open()) === false) | 1093 if (($finfo = finfo_open()) === FALSE) |
1094 { | 1094 { |
1095 stLogError("Internal error. Failed to initialize finfo()."); | 1095 stLogError("Internal error. Failed to initialize finfo()."); |
1096 return stError("Internal error, failed to probe file."); | 1096 return stError("Internal error, failed to probe file."); |
1097 } | 1097 } |
1098 | 1098 |
1142 $sql = stPrepareSQL( | 1142 $sql = stPrepareSQL( |
1143 "INSERT INTO files (origname,filetype,filesize,entry_id,uploader_id,uploadtype,utime) ". | 1143 "INSERT INTO files (origname,filetype,filesize,entry_id,uploader_id,uploadtype,utime) ". |
1144 "VALUES (%s,%s,%d,%d,%d,%s,%d)", | 1144 "VALUES (%s,%s,%d,%d,%d,%s,%d)", |
1145 $origName, $fileType, $fileSize, $entry["id"], $uploaderID, $type, time()); | 1145 $origName, $fileType, $fileSize, $entry["id"], $uploaderID, $type, time()); |
1146 | 1146 |
1147 if (($fileID = stExecSQLInsert($sql)) === false) | 1147 if (($fileID = stExecSQLInsert($sql)) === FALSE) |
1148 return stFileError($uploaderID, | 1148 return stFileError($uploaderID, |
1149 "Failed to add new ".$type." file for entry #".$entry["id"]." '".$origName."'.", | 1149 "Failed to add new ".$type." file for entry #".$entry["id"]." '".$origName."'.", |
1150 "Internal error. Failed to add new file."); | 1150 "Internal error. Failed to add new file."); |
1151 | 1151 |
1152 // Compute storage filename | 1152 // Compute storage filename |
1158 $fileID, | 1158 $fileID, |
1159 $fileExt); | 1159 $fileExt); |
1160 | 1160 |
1161 // Update entry with generated filename | 1161 // Update entry with generated filename |
1162 $sql = stPrepareSQL("UPDATE files SET filename=%s WHERE id=%d", $fileName, $fileID); | 1162 $sql = stPrepareSQL("UPDATE files SET filename=%s WHERE id=%d", $fileName, $fileID); |
1163 if (stExecSQL($sql) === false) | 1163 if (stExecSQL($sql) === FALSE) |
1164 return stFileError($uploaderID, | 1164 return stFileError($uploaderID, |
1165 "Failed to update newly created files entry #".$fileID." with generated filename '".$fileName."'!", | 1165 "Failed to update newly created files entry #".$fileID." with generated filename '".$fileName."'!", |
1166 "Internal error. Failed to add new file."); | 1166 "Internal error. Failed to add new file."); |
1167 | 1167 |
1168 // Update entry's reference | 1168 // Update entry's reference |
1169 $sql = stPrepareSQL("UPDATE entries SET ".$field."=%d WHERE id=%d", $fileID, $entry["id"]); | 1169 $sql = stPrepareSQL("UPDATE entries SET ".$field."=%d WHERE id=%d", $fileID, $entry["id"]); |
1170 if (stExecSQL($sql) === false) | 1170 if (stExecSQL($sql) === FALSE) |
1171 return stFileError($uploaderID, | 1171 return stFileError($uploaderID, |
1172 "Failed to update entry #".$entry["id"]." ".$type." ID!", | 1172 "Failed to update entry #".$entry["id"]." ".$type." ID!", |
1173 "Internal error. Failed to add new file."); | 1173 "Internal error. Failed to add new file."); |
1174 | 1174 |
1175 // Return file entry | 1175 // Return file entry |
1176 if (($res = stFetchSQL("SELECT * FROM files WHERE id=".$fileID)) === false) | 1176 if (($res = stFetchSQL("SELECT * FROM files WHERE id=".$fileID)) === FALSE) |
1177 return stFileError($uploaderID, | 1177 return stFileError($uploaderID, |
1178 "Failed to fetch newly generated files entry #".$fileID, | 1178 "Failed to fetch newly generated files entry #".$fileID, |
1179 "Internal error. Failed to add new file."); | 1179 "Internal error. Failed to add new file."); |
1180 | 1180 |
1181 return $res; | 1181 return $res; |
1197 !stChkRequestItem("entry_id", $entryID, | 1197 !stChkRequestItem("entry_id", $entryID, |
1198 array(CHK_TYPE, VT_INT, "Invalid entry ID."))) | 1198 array(CHK_TYPE, VT_INT, "Invalid entry ID."))) |
1199 return FALSE; | 1199 return FALSE; |
1200 | 1200 |
1201 // Check entry existence | 1201 // Check entry existence |
1202 if (($entry = stFetchSQL("SELECT * FROM entries WHERE id=".$entryID)) === false) | 1202 if (($entry = stFetchSQL("SELECT * FROM entries WHERE id=".$entryID)) === FALSE) |
1203 return stFileError($userID, | 1203 return stFileError($userID, |
1204 "Entry ID #".$entryID." does not exist in the entries table?", | 1204 "Entry ID #".$entryID." does not exist in the entries table?", |
1205 "Entry does not exist??"); | 1205 "Entry does not exist??"); |
1206 | 1206 |
1207 if (($compo = stFetchSQL("SELECT * FROM compos WHERE id=".$entry["compo_id"])) === false) | 1207 if (($compo = stFetchSQL("SELECT * FROM compos WHERE id=".$entry["compo_id"])) === FALSE) |
1208 return stFileError($userID, | 1208 return stFileError($userID, |
1209 "Compo ID #".$entry["compo_id"]." in entry ID #".$entryID." does not exist!", | 1209 "Compo ID #".$entry["compo_id"]." in entry ID #".$entryID." does not exist!", |
1210 "Compo does not exist??"); | 1210 "Compo does not exist??"); |
1211 | 1211 |
1212 // Check target path existence / writability | 1212 // Check target path existence / writability |
1230 | 1230 |
1231 // Check permissions for non-admins | 1231 // Check permissions for non-admins |
1232 if ($userID != 0) | 1232 if ($userID != 0) |
1233 { | 1233 { |
1234 // Check if the user even exists, just in case | 1234 // Check if the user even exists, just in case |
1235 if (($user = stFetchSQL("SELECT * FROM attendees WHERE id=".$userID)) === false) | 1235 if (($user = stFetchSQL("SELECT * FROM attendees WHERE id=".$userID)) === FALSE) |
1236 return stFileError($userID, | 1236 return stFileError($userID, |
1237 "User ID #".$userID." does not exist??", | 1237 "User ID #".$userID." does not exist??", |
1238 "You do not exist. Go away."); | 1238 "You do not exist. Go away."); |
1239 | 1239 |
1240 if ($entry["owner_id"] != $userID) | 1240 if ($entry["owner_id"] != $userID) |
1290 if ($errorSet) | 1290 if ($errorSet) |
1291 return FALSE; | 1291 return FALSE; |
1292 | 1292 |
1293 | 1293 |
1294 // Check file properties .. | 1294 // Check file properties .. |
1295 if (($fileInfo = stProbeFileInfo($tmpFilename)) === false) | 1295 if (($fileInfo = stProbeFileInfo($tmpFilename)) === FALSE) |
1296 return FALSE; | 1296 return FALSE; |
1297 | 1297 |
1298 if ($uploadType == "preview" && !isset($fileInfo["type"])) | 1298 if ($uploadType == "preview" && !isset($fileInfo["type"])) |
1299 return stError("Preview file upload is not one of the supported preview file types."); | 1299 return stError("Preview file upload is not one of the supported preview file types."); |
1300 | 1300 |
1301 // Get original extension | 1301 // Get original extension |
1302 if (($fileExt = $fileInfo["fext"]) === false) | 1302 if (($fileExt = $fileInfo["fext"]) === FALSE) |
1303 { | 1303 { |
1304 $fileExt = "bin"; | 1304 $fileExt = "bin"; |
1305 if (($epos = strrpos($orgFilename, ".")) !== false) | 1305 if (($epos = strrpos($orgFilename, ".")) !== FALSE) |
1306 $fileExt = substr($orgFilename, $epos + 1); | 1306 $fileExt = substr($orgFilename, $epos + 1); |
1307 } | 1307 } |
1308 | 1308 |
1309 // Update current or add new file entry | 1309 // Update current or add new file entry |
1310 if (($fentry = stAddFileEntry($entry, $uploadType, $orgFilename, $fileSize, $fileExt, $fileInfo["id"], $userID)) === false) | 1310 if (($fentry = stAddFileEntry($entry, $uploadType, $orgFilename, $fileSize, $fileExt, $fileInfo["id"], $userID)) === FALSE) |
1311 return FALSE; | 1311 return FALSE; |
1312 | 1312 |
1313 // Set permissions before moving the file | 1313 // Set permissions before moving the file |
1314 if (chmod($tmpFilename, stGetSetting($uploadType."PathPerms")) === false) | 1314 if (chmod($tmpFilename, stGetSetting($uploadType."PathPerms")) === FALSE) |
1315 return stFileError($userID, | 1315 return stFileError($userID, |
1316 "Could not set permissions for uploaded file '".$tmpFilename."'.", | 1316 "Could not set permissions for uploaded file '".$tmpFilename."'.", |
1317 "Internal error. Could not set permissions for uploaded file. Contact site admins."); | 1317 "Internal error. Could not set permissions for uploaded file. Contact site admins."); |
1318 | 1318 |
1319 // Move file to its destination | 1319 // Move file to its destination |
1320 $dstFilename = stMakePath(FALSE, TRUE, array(stGetSetting("entryPath"), $compo["cpath"], $fentry["filename"])); | 1320 $dstFilename = stMakePath(FALSE, TRUE, array(stGetSetting("entryPath"), $compo["cpath"], $fentry["filename"])); |
1321 if (@move_uploaded_file($tmpFilename, $dstFilename) === false) | 1321 if (@move_uploaded_file($tmpFilename, $dstFilename) === FALSE) |
1322 return stFileError($userID, | 1322 return stFileError($userID, |
1323 "Could not move uploaded file '".$tmpFilename."' to '".$dstFilename."'.", | 1323 "Could not move uploaded file '".$tmpFilename."' to '".$dstFilename."'.", |
1324 "Internal error. Deploying uploaded file failed! Contact site admins."); | 1324 "Internal error. Deploying uploaded file failed! Contact site admins."); |
1325 | 1325 |
1326 return TRUE; | 1326 return TRUE; |