function ajaxProcessLayout()
 {
     global $wpdb;
     if (isset($_POST['type']) && $_POST['type']) {
         $save_type = $_POST['type'];
     } else {
         $save_type = null;
     }
     if ($save_type == 'addItemToLayout') {
         $layout = isset($_POST['layout']) ? $_POST['layout'] : '';
         $uId = isset($_POST['parentId']) ? intval($_POST['parentId']) : '';
         if ($layout != '' && $uId != '') {
             $toEcho = wipfr_get_layout_for_setting($layout, $uId, 0, true);
             echo $toEcho;
             die;
         }
     } else {
         if ($save_type == 'addContentToLayout') {
             $uId = isset($_POST['uId']) ? intval($_POST['uId']) : '';
             $contentValue = isset($_POST['contentValue']) ? $_POST['contentValue'] : "";
             $possibleID = isset($_POST['possibleID']) ? intval($_POST['possibleID']) : '';
             if ($uId != "" && $contentValue != "" && $possibleID != "") {
                 echo wipfr_get_layout_for_setting($contentValue, $possibleID, $uId);
                 die;
             }
         } else {
             if ($save_type == 'addContentToBox') {
                 $formname = isset($_POST['formname']) ? $_POST['formname'] : '';
                 $formvalue = isset($_POST['formvalue']) ? $_POST['formvalue'] : '';
                 if ($formname != "" && $formvalue != "") {
                     $theID = str_replace('[', ',', $formname);
                     $theID = str_replace(']', '', $theID);
                     $findIt = explode(",", $theID);
                     $html = wipfr_content_for_column($formvalue, $findIt[1], $findIt[2]);
                     $return = array("col" => $findIt[1], "parID" => $findIt[2], "html" => $html);
                     echo json_encode($return);
                     die;
                 }
             }
         }
     }
     die;
 }
 function ajaxProcessLayout()
 {
     global $wpdb;
     if (isset($_POST['type']) && $_POST['type']) {
         $save_type = $_POST['type'];
     } else {
         $save_type = null;
     }
     if ($save_type == 'addItemToLayout') {
         $layout = isset($_POST['layout']) ? $_POST['layout'] : '';
         if ($layout != '') {
             $currentParent = get_option('wipfr_parent_home_layout');
             $currentParentDraft = get_option('wipfr_parent_home_layout_draft');
             $insertID = array();
             $uId = 1;
             $toEcho = '';
             $parentdrafting = '';
             if (!empty($currentParent) && is_array($currentParent)) {
                 $biggest = array();
                 foreach ($currentParent as $x => $n) {
                     $biggest[$x] = $x;
                 }
                 $bigNum = max($biggest);
                 $uId = intval($bigNum) + 1;
                 //possible db id
                 if (!empty($currentParentDraft) && is_array($currentParentDraft)) {
                     $biggestDraft = array();
                     foreach ($currentParentDraft as $xd => $nd) {
                         $biggestDraft[$xd] = $xd;
                     }
                     if (array_key_exists($uId, $biggestDraft)) {
                         $bigNumDraft = max($biggestDraft);
                         $uId = $bigNumDraft + 1;
                         //possible db id
                     }
                 }
             } else {
                 if (!empty($currentParentDraft) && is_array($currentParentDraft)) {
                     $biggestDraft = array();
                     foreach ($currentParentDraft as $xd => $nd) {
                         $biggestDraft[$xd] = $xd;
                     }
                     if (array_key_exists($uId, $biggestDraft)) {
                         $bigNumDraft = max($biggestDraft);
                         $uId = $bigNumDraft + 1;
                         //possible db id
                     }
                 }
             }
             $insertID[$uId] = array("id" => $uId, "type" => $layout);
             if (!empty($currentParentDraft) && is_array($currentParentDraft)) {
                 $parentdrafting = $currentParentDraft + $insertID;
             } else {
                 $parentdrafting = $insertID;
             }
             update_option('wipfr_parent_home_layout_draft', $parentdrafting);
             $toEcho = wipfr_get_layout_for_setting($layout, $uId);
             echo $toEcho;
             die;
         }
     } else {
         if ($save_type == 'addContentToLayout') {
             $uId = isset($_POST['uId']) ? $_POST['uId'] : 0;
             $contentValue = isset($_POST['contentValue']) ? $_POST['contentValue'] : "";
             $currentContent = get_option('wipfr_parent_home_content');
             $currentContentDraft = get_option('wipfr_parent_home_content_draft');
             $possibleID = 1;
             $drafting = '';
             if (!empty($uId) && $contentValue != "") {
                 if (!empty($currentContent) && is_array($currentContent)) {
                     $biggest = array();
                     foreach ($currentContent as $x => $n) {
                         $biggest[$x] = $x;
                     }
                     $bigNum = max($biggest);
                     $possibleID = $bigNum + 1;
                     //possible db id
                     if (!empty($currentContentDraft) && is_array($currentContentDraft)) {
                         $biggestDraft = array();
                         foreach ($currentContentDraft as $xd => $nd) {
                             $biggestDraft[$xd] = $xd;
                         }
                         if (array_key_exists($possibleID, $biggestDraft)) {
                             $bigNumDraft = max($biggestDraft);
                             $possibleID = $bigNumDraft + 1;
                             //possible db id
                         }
                     }
                 } else {
                     if (!empty($currentContentDraft) && is_array($currentContentDraft)) {
                         $biggestDraft = array();
                         foreach ($currentContentDraft as $xd => $nd) {
                             $biggestDraft[$xd] = $xd;
                         }
                         if (array_key_exists($possibleID, $biggestDraft)) {
                             $bigNumDraft = max($biggestDraft);
                             $possibleID = $bigNumDraft + 1;
                             //possible db id
                         }
                     }
                 }
                 $contentDraft[$possibleID] = array('id' => $possibleID, 'parent' => $uId, 'type' => $contentValue);
                 if (!empty($currentContentDraft) && is_array($currentContentDraft)) {
                     $drafting = $currentContentDraft + $contentDraft;
                 } else {
                     $drafting = $contentDraft;
                 }
                 update_option('wipfr_parent_home_content_draft', $drafting);
                 echo wipfr_get_layout_for_setting($contentValue, $possibleID, $uId);
                 die;
             }
         } else {
             if ($save_type == 'addContentToBox') {
                 $formname = isset($_POST['formname']) ? $_POST['formname'] : '';
                 $formvalue = isset($_POST['formvalue']) ? $_POST['formvalue'] : '';
                 if ($formname != "" && $formvalue != "") {
                     $theID = str_replace('[', ',', $formname);
                     $theID = str_replace(']', '', $theID);
                     $findIt = explode(",", $theID);
                     $html = wipfr_content_for_column($formvalue, $findIt[1], $findIt[2]);
                     $return = array("col" => $findIt[1], "parID" => $findIt[2], "html" => $html);
                     echo json_encode($return);
                     die;
                 }
             }
         }
     }
     die;
 }