%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /var/www/pn/beta/64801_wp-content/themes/intosai/lib/user_functions/
Upload File :
Create Path :
Current File : /var/www/pn/beta/64801_wp-content/themes/intosai/lib/user_functions/edit_project.php

<?php require_once("../../../../../wp-load.php");

if(isset($_GET['editproject'])){

    //SET UPP CONTENT VARIABLES AND SANITIZE THEM
    $postStatus                 = strip_tags(htmlspecialchars($_POST['projectPostStatus']));
    $projectID                  = strip_tags(htmlspecialchars($_POST['projectConnection']));
    $projectName                = strip_tags(htmlspecialchars($_POST['projectName']));
    $projectStatus              = strip_tags(htmlspecialchars($_POST['status']));
    $projectBenLevel            = strip_tags(htmlspecialchars($_POST['benLevel']));
    $projectBenSAI              = $_POST['benSai'];
    $projectINTOSAIRegion       = $_POST['intosaiRegion'];
    $projectDesc                = $_POST['desc'];
    $projectInit                = strip_tags(htmlspecialchars($_POST['initiated']));
    $projectFurtherLink         = strip_tags(htmlspecialchars($_POST['furtherLink']));
    $projectCPBenSaiReCom       = strip_tags(htmlspecialchars($_POST['contactBRC']));
    $projectFunding             = $_POST['funding'];
    $projectFundingCustom       = strip_tags(htmlspecialchars($_POST['sof_custom']));
    $projectCPDonor             = strip_tags(htmlspecialchars($_POST['contactDonor']));
    $projectImpAge              = strip_tags(htmlspecialchars($_POST['implementingAgency']));
    $projectCPImpPart           = strip_tags(htmlspecialchars($_POST['implementingContact']));
    $projectFrom                = strip_tags(htmlspecialchars($_POST['from']));
    $projectTo                  = strip_tags(htmlspecialchars($_POST['to']));
    $projectBudget              = strip_tags(htmlspecialchars($_POST['budget']));
    $projectSupType             = strip_tags(htmlspecialchars($_POST['supportType']));
    $projectSupModal            = strip_tags(htmlspecialchars($_POST['supportModal']));
    $projectSupCats             = $_POST['supportCats'];
    $projectSupBased            = strip_tags(htmlspecialchars($_POST['supportBased']));
    $projectLinkedProj          = $_POST['linkedProjects'];
    $projectOtherInfo           = $_POST['otherInfo'];
    $publishStatus              = strip_tags(htmlspecialchars($_POST['publishStatus']));
    $draftCreated               = strip_tags(htmlspecialchars($_POST['creation']));

    $wdiTerms = array();
    foreach($projectBenSAI as $benSAI){
        array_push($wdiTerms, $benSAI);
    }

    $projLinks = array();
    foreach($projectLinkedProj as $project){
        array_push($projLinks, $project);
    }

    $regions = ''; $r = 1;
    foreach($projectINTOSAIRegion as $INTOSAIRegion){
        if($r != 1){
            $regions .= ', ';
        }

        $regions .= $INTOSAIRegion;

        $r++;
    }

    $sources = ''; $s = 1;
    foreach($projectFunding as $source){
        if($s != 1){
            $sources .= ', ';
        }

        $sources .= $source;

        $s++;
    }

    $supCover = ''; $sC = 1;
    foreach($projectSupCats as $supCat){
        if($sC != 1){
            $supCover .= ', ';
        }

        $supCover .= $supCat;

        $sC++;
    }

    $allowedTags = '<br><strong><b><em><i><ul><li>';

    if($postStatus == 'pending') : //THE PROJECT IS NOT YET PUBLISHED
        $postType = 'project';

        $project = array(
            'ID'                =>      $projectID,
            'post_type'         =>      $postType,
            'post_status'       =>      'pending',
            'post_title'        =>      strip_tags($projectName),
            'post_content'      =>      strip_tags($projectDesc, $allowedTags),
            'tax_input'    => array(
                'wdi'   =>  $wdiTerms
            ),
            'meta_input'        =>      array(
                'project_status'                        =>  $projectStatus,
                'beneficiary_level'                     =>  $projectBenLevel,
                'intosai_region'                        =>  $regions,
                'project_initiated'                     =>  $projectInit,
                'further_info'                          =>  $projectFurtherLink,
                'cp_ben-sai_region_committee'           =>  $projectCPBenSaiReCom,
                'source_funding'                        =>  $sources,
                'source_funding_custom'                 =>  $projectFundingCustom,
                'cp_donor'                              =>  $projectCPDonor,
                'imp_agencys'                           =>  $projectImpAge,
                'cp_imp-partners'                       =>  $projectCPImpPart,
                'duration_from'                         =>  $projectFrom,
                'duration_to'                           =>  $projectTo,
                'total_budget'                          =>  $projectBudget,
                'type_of_support'                       =>  $projectSupType,
                'support_modality'                      =>  $projectSupModal,
                'support_cats_covered'                  =>  $supCover,
                'support_based_on'                      =>  $projectSupBased,
                'project_connections'                   =>  $projLinks,
                'other_info'                            =>  strip_tags($projectOtherInfo, $allowedTags),
                'publish_status'                        =>  $publishStatus,
                'draft_creation'                        =>  $draftCreated,
            ),
        );

        $update_project = wp_update_post($project);

        $revisionCreated = false;

        if($publishStatus == 'publish'){
            $publishNewProject  = true;
        }else{
            $publishNewProject  = false;
        }

    else : //THE PROJECT IS PUBLISHED AND A REVISION IS SAVED
        $postType = 'project_revisions';

        $project = array(
            'post_type'         =>      $postType,
            'post_status'       =>      'pending',
            'post_title'        =>      strip_tags($projectName),
            'post_content'      =>      strip_tags($projectDesc, $allowedTags),
            'tax_input'    => array(
                'wdi'   =>  $wdiTerms
            ),
            'meta_input'        =>      array(
                'revision_for_id'                       =>  $projectID,
                'project_status'                        =>  $projectStatus,
                'beneficiary_level'                     =>  $projectBenLevel,
                'intosai_region'                        =>  $regions,
                'project_initiated'                     =>  $projectInit,
                'further_info'                          =>  $projectFurtherLink,
                'cp_ben-sai_region_committee'           =>  $projectCPBenSaiReCom,
                'source_funding'                        =>  $sources,
                'source_funding_custom'                 =>  $projectFundingCustom,
                'cp_donor'                              =>  $projectCPDonor,
                'imp_agencys'                           =>  $projectImpAge,
                'cp_imp-partners'                       =>  $projectCPImpPart,
                'duration_from'                         =>  $projectFrom,
                'duration_to'                           =>  $projectTo,
                'total_budget'                          =>  $projectBudget,
                'type_of_support'                       =>  $projectSupType,
                'support_modality'                      =>  $projectSupModal,
                'support_cats_covered'                  =>  $supCover,
                'support_based_on'                      =>  $projectSupBased,
                'project_connections'                   =>  $projLinks,
                'other_info'                            =>  strip_tags($projectOtherInfo, $allowedTags),
                'publish_status'                        =>  $publishStatus,
                'draft_creation'                        =>  $draftCreated,
            ),
        );

        $update_project = wp_insert_post($project);

        $revisionCreated    = true;
        $publishNewProject  = false;

    endif;


    if(!is_wp_error($update_project)){ //PROJECT ADDED

        $adminEmail = 'admin@saidevelopment.org';

        if($publishNewProject){
            /************************************* CONSTRUCT EMAIL *************************************/
            /*----------------------------------- Sends to the admin ----------------------------------*/
            include('mailer.php');

            $form_id = 'Publish project';

            //TITLE IN MAIL
            $sub = "Project awaits approval";

            //SHORT EXCERPT VIEWED IN EG. GMAIL
            $excerpt = "A user has flaged a project for publishing";

            //MAIN MESSAGE IN MAIL
            $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>{$sub}</h1>
            <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:{$color};'>{$excerpt}</h2>
            You can review and publish the project by pressing the link below.<br/>
            <br/>
            View the project: <a href='{$site_url}wp-admin/post.php?post={$update_project}&action=edit' style='color:{$color};'>{$projectName}</a>";

            $from = 'no-reply@saiddevelopment.org';
            $headers = array('Content-Type: text/html; charset=UTF-8');

            //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers);
            wp_mail($adminEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers);
            $updateCode = 'pending_publication';
        }

        if($revisionCreated){
            /************************************* CONSTRUCT EMAIL *************************************/
            /*----------------------------------- Sends to the admin ----------------------------------*/
            include('mailer.php');

            $form_id = 'Edit project';

            //TITLE IN MAIL
            $sub = "Review changes to project";

            //SHORT EXCERPT VIEWED IN EG. GMAIL
            $excerpt = "A user has edited their project";

            //MAIN MESSAGE IN MAIL
            $message = "<h1 style='font-size:24px;line-height:30px;margin:0 0 0;'>{$sub}</h1>
            <h2 style='font-size:18px;font-weight:400;line-height:30px;margin:0 0 20px;color:{$color};'>{$excerpt}</h2>
            A user has made changes to one of their published projects.<br/>
            The changes need to be reviewd before they are published.
            <br/>
            View the changes and publish: <a href='{$site_url}wp-admin/post.php?post={$update_project}&action=edit' style='color:{$color};'>{$projectName}</a>";

            $from = 'no-reply@saiddevelopment.org';
            $headers = array('Content-Type: text/html; charset=UTF-8');

            //wp_mail('kim@noboxsolutions.se', $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers);
            wp_mail($adminEmail, $sub, smtp_mail($sub,$message,$excerpt,$fromUrl,$form_id), $headers);

            $updateCode = 'update_pending';
        }

        header("Location: /my-projects/?project_updated&{$updateCode}");
        exit;
    }else{ //THERE WAS AN ERROR CREATING THE PROJECT
        header("Location: /my-projects/?add_update_error");
        exit;
    }

}
?>

Zerion Mini Shell 1.0