Ejemplo n.º 1
0
 public function actionDelete()
 {
     $data = $_POST;
     $project = Projects::model()->findByPk($data['project_id']);
     if (Yii::app()->user->name != $project['created_by']) {
         echo CJSON::encode(array('type' => 'error', 'data' => 'Only those who created the project can delete it'));
         return;
     }
     // SQL query for project data
     // $query = "\n"."INSERT INTO `projects` ";
     // $keys = "(";
     // $values = " VALUES\n(";
     // $col_num = count(Projects::model()->attributes);
     // foreach($project as $key => $value) {
     //     $keys .= "`".$key."`";
     //     $values .= ($value === null)? "NULL" : "'".$value."'";
     //     $col_num--;
     //     if ($col_num > 0) {
     //         $keys .= ', ';
     //         $values .= ', ';
     //     }
     // }
     // $keys .= ")";
     // $values .= ")";
     // $query .= $keys.$values.";\n";
     // //SQL query for contact person data
     // $contact_persons = ProjectContactPersons::model()->findAll('project_id=:project_id', array(':project_id'=>$data['project_id']));
     // if (count($contact_persons) > 0) {
     //     $query .=  "\n"."INSERT INTO `project_contact_persons` ";
     //     $con_attr = ProjectContactPersons::model()->attributes;
     //     // collect attributes
     //     $keys = "(";
     //     $col_num = count($con_attr);
     //     foreach ($con_attr as $key => $values) {
     //         $keys .= "`".$key."`";
     //         $col_num--;
     //         if ($col_num > 0) {
     //             $keys .= ', ';
     //         }
     //     }
     //     $keys .= ")";
     //     // collect rows
     //     $values = " VALUES";
     //     $con_count = count($contact_persons);
     //     foreach($contact_persons as $contact) {
     //         $values .= "\n(";
     //         $col_num = count($con_attr);
     //         foreach($contact as $key => $value) {
     //             $values .= ($value === null)? "NULL" : "'".$value."'";
     //             $col_num--;
     //             if ($col_num > 0) {
     //                 $values .= ', ';
     //             }
     //         }
     //         $values .= ")";
     //         $con_count--;
     //         if ($con_count > 0) {
     //             $values .= ", ";
     //         }
     //     }
     //     $query .= $keys.$values.";\n";
     // }
     // //SQL query for point person data
     // $point_persons = ProjectPointPersons::model()->findAll('project_id=:project_id', array(':project_id'=>$data['project_id']));
     // if (count($point_persons) > 0) {
     //     $query .=  "\n"."INSERT INTO `project_point_persons` ";
     //     $pnt_attr = ProjectPointPersons::model()->attributes;
     //     // collect attributes
     //     $keys = "(";
     //     $col_num = count($pnt_attr);
     //     foreach ($pnt_attr as $key => $values) {
     //         $keys .= "`".$key."`";
     //         $col_num--;
     //         if ($col_num > 0) {
     //             $keys .= ', ';
     //         }
     //     }
     //     $keys .= ")";
     //     // collect rows
     //     $values = " VALUES";
     //     $pnt_count = count($point_persons);
     //     foreach($point_persons as $point) {
     //         $values .= "\n(";
     //         $col_num = count($pnt_attr);
     //         foreach($point as $key => $value) {
     //             $values .= ($value === null)? "NULL" : "'".$value."'";
     //             $col_num--;
     //             if ($col_num > 0) {
     //                 $values .= ', ';
     //             }
     //         }
     //         $values .= ")";
     //         $pnt_count--;
     //         if ($pnt_count > 0) {
     //             $values .= ", ";
     //         }
     //     }
     //     $query .= $keys.$values.";\n";
     // }
     // if (file_put_contents('db_files/deleted_projects.sql', $query, FILE_APPEND) === false) {
     //     echo CJSON::encode(array(
     //         'type' => 'error',
     //         'data' => '',
     //     ));
     // } else {
     // delete record here
     Projects::model()->deleteByPk($data['project_id']);
     ProjectContactPersons::model()->deleteAll('project_id=:project_id', array(':project_id' => $data['project_id']));
     ProjectPointPersons::model()->deleteAll('project_id=:project_id', array(':project_id' => $data['project_id']));
     echo CJSON::encode(array('type' => 'success', 'data' => ''));
     // }
 }
Ejemplo n.º 2
0
 public function actionDelete()
 {
     $data = $_POST;
     if (!empty($data)) {
         ProjectContactPersons::model()->deleteByPk(array('project_id' => (int) $data['project_id'], 'email' => (string) $data['email']));
         echo CJSON::encode(array('type' => 'success', 'data' => ''));
     } else {
         echo CJSON::encode(array('type' => 'error', 'data' => 'CSRF_ERROR: CSRF Token did not match'));
     }
 }