kirchaj
Posts: 215
|
Posted: 02/18/2014, 3:10 PM |
|
Hey All,
I am having a little difficulty. I have a table where a user can delete a record but I want to check and see if there are any files that have been uploaded by the user first. If there are files, I do not want to process the delete. I have used a custom Delete from table to actually remove the record. From there I have tried Before Delete and Before Build Delete with the following code
$db = new clsDBportfolio();
echo "I am in before delete";
$where = "crssem_index=".$student_course->crssem_index->GetValue()."' and stu_id='".$student_course->stu_id->GetValue()."'";
echo $where;
$stu_upld_cnt = CCDLOOKUP("count(*)","stu_upload_filename",$where,$db);
if ($stu_upld_cnt) {
$student_course->DeleteAllowed = false;
$student_course->Errors->addError("Student cannot be deleted. Student has files and scores in this course.");
}
I get nothing from the echoes or the error message and the delete runs no matter what. Any ideas what I am doing wrong?
TK
|
|
|
eratech
Posts: 513
|
Posted: 02/18/2014, 4:55 PM |
|
You might check the if ($stu_upld_cnt) - the 'count(*)' will return 0 if nothing found, so it's possible that the 'if' statement is going 'true' no matter what value is returned.
Try checking for zero specifically and see if that helps.
As for the echos not printing, I'm not sure - you could always stick them into the Errors as well, and that will force them to appear if the validation is on.
And you are right doing the `DeleteAllowed = false` in the Before Delete (per Manual) but I don't think it works if set in the 'Before Build Delete'
Sorry I couldn't help more
Eric
_________________
CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia |
|
|
kirchaj
Posts: 215
|
Posted: 02/18/2014, 7:18 PM |
|
Eric,
Thanks so much. You were right on and this code shows the right output but for some reason the Delete is still being processed. Could it be because I am using a custom delete from table?
$db = new clsDBportfolio();
//echo "I am in before build delete";
$where = "crssem_index=".$student_course->crssem_index->GetValue()." and stu_id='".$student_course->stu_id->GetValue()."'";
//echo $where;
$stu_upld_cnt = CCDLookUp("count(*)","student_upload",$where,$db);
//echo "upload count =";
//echo $stu_upld_cnt;
if ($stu_upld_cnt > 0) {
$student_course->DeleteAllowed = false;
$student_course->Errors->addError("Student cannot be deleted. Student has files/scores for this course.");
}
$db->close();
Thanks again.
TK
|
|
|
eratech
Posts: 513
|
Posted: 02/18/2014, 10:45 PM |
|
The Custom Delete should be fine - the actual 'Delete' (and update/insert) work from whatever you select (Table/SQL/SP) and the events should work either way.
You are setting the `DeleteAllowed` - so check in the actual Delete code, does it check for that flag (like the manual says) or is there another flag that it checks. I'm away from my CCS install otherwise I would check myself.
E
_________________
CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia |
|
|
kirchaj
Posts: 215
|
Posted: 02/19/2014, 7:08 AM |
|
Eric,
You were right on. I had to undo some of the playing I did yesterday but the following code in the BeforeDelete event. Thanks so much for the assistance.
$db = new clsDBportfolio();
$where = "crssem_index=".$student_course->crssem_index->GetValue()." and stu_id='".$student_course->stu_id->GetValue()."'";
$stu_upld_cnt = CCDLookUp("count(*)","student_upload",$where,$db);
if ($stu_upld_cnt > 0) {
$student_course->DeleteAllowed = false;
$student_course->Errors->addError("Student cannot be deleted. Student has files/scores within this course.");
} else {
$student_course->DeleteAllowed = true;
}
$db->close();
|
|
|
|