function content_edit_content_form_submit

7.x content.module content_edit_content_form_submit(&$form, &$form_state)
6.x content.module content_edit_content_form_submit(&$form, &$form_state)
4.x content.module content_edit_content_form_submit(&$form, $form_state)
5.x content.module content_edit_content_form_submit(&$form, $form_state)

Submit handler for the edit content form.

_state

Parameters

unknown_type $form:

File

modules/content/content.module, line 1497

Code

function content_edit_content_form_submit(&$form, &$form_state) {
  global $user;

  $values = $form_state ["values"];
  $cid = $values ['cid'];
  $type = $values ["type"];

  // are we trying to delete?
  if (isset($values ['submit_delete']) && trim($values ['submit_delete']) != '') {
    // Yes, we are deleting!

    $content = content_load($cid);


    if (!content_user_access('delete', $content->cid)) {
      fp_add_message(t("Sorry, you do not have permission to delete this content."));
      fp_goto("<front>");
      return;
    }



    $content->delete_flag = 1;
    content_save($content);



    watchdog("content", "delete cid:$cid, type:$type", array());

    // find out if we should redirect anywhere in particular for this deletion.
    if (isset($form ['#redirect'])) {
      fp_add_message(t("The content was deleted successfully."));
      $form ['#redirect']['query'] .= "&del=" . $content->cid;
    }
    else {
      // No redirect was specified, so let's send us to the home page.
      fp_add_message(t("The content was deleted successfully."));
      $form ['#redirect']['path'] = "<front>";
    }
    return;

  }


  $now = time();

  $types = content_get_types();


  // Does the user have permission to edit/add this content?  
  $access_action = "add";
  $var = $type;
  if ($cid !== "new") {
    $access_action = "edit";
    $var = $cid;
  }

  if (!content_user_access($access_action, $var)) {
    fp_add_message(t("Sorry, you do not have permission to @action that content type.", array("@action" => $access_action)));
    fp_goto("admin-tools/content");
    return;
  }

  // Assemble into a content object, then call content_save();
  if ($values ['cid'] == 'new') {
    // This is a NEW content obj!
    $content = new stdClass();
    $content->type = $type;
    $content->cid = "new";
    $content->published = 1;
    $content->delete_flag = 0;
    content_save($content); // Do an initial save, so we get its cid back.    
  }
  else {
    // This is an EXISTING content.  Load it.
    $content = content_load($values ['cid']);
  }

  $cid = $content->cid;

  // Clean the title of any XSS attempts
  $title = filter_markup($values ['title']);

  $content->title = $title; // required

  // set published status.  0 for not, 1 for published
  $content->published = (bool) $values ['published'];

  // Add in our new field values.  
  foreach ($types [$type]['fields'] as $fieldname => $details) {
    if ($details ['type'] != 'cfieldset') {



      if ($details ['type'] == 'datetime-local') {
        // Since this is datetime-local, the value is actually already in the user's timezone.
        // We want to CHANGE THIS TO UTC, so it saves in the database as UTC.
        $val_ts = @strtotime($values [$fieldname]);
        $utc_ts = convert_time($val_ts, fp_get_user_timezone(), 'UTC');
        $values [$fieldname] = date('Y-m-d H:i:s', $utc_ts);
      }

      // Do the same for "time" field type.  We need to convert to UTC from the user's timezone.
      if ($details ['type'] == 'time') {
        // Since this is time, the value is actually already in the user's timezone.
        // We want to CHANGE THIS TO UTC, so it saves in the database as UTC.
        $val_ts = @strtotime("2000-01-01 " . $values [$fieldname]); // give a bogus date just so our times make since.
        $utc_ts = convert_time($val_ts, fp_get_user_timezone(), 'UTC');
        $values [$fieldname] = date('H:i', $utc_ts);
      }


      // If this field type is "file" then we are going to do something special with it
      // don't need to do this if we are just editing an existing content node and hitting "save"
      if ($details ['type'] == 'file') {

        $uploaded_files = fp_re_array_files($_FILES [$fieldname]); // makes them easier to work with.

        $fid = "";
        foreach ($uploaded_files as $file) {

          if ($file && $file ['name'] != '') {
            // Now, save to the content_files table.
            $fid .= content_add_new_uploaded_file($file, $cid) . ",";
          }

        } // foreach

        // Do we have any previously uploaded files we need to include?
        if (@$form_state ['values']['previous_upload_' . $fieldname] != "") {
          $fid .= "," . $form_state ['values']['previous_upload_' . $fieldname] . ",";
        }

        $fid = ltrim($fid, ",");
        for ($t = 0; $t < 10; $t++) {
          $fid = str_replace(",,", ",", $fid); // get rid of any duplicate commas
        }
        $fid = rtrim($fid, ","); // trim any extra commas
        $values [$fieldname] = $fid;


      } // if details = file




      $content->{'field__' . $fieldname}['value'] = @$values [$fieldname];
    }
    else {
      foreach ($details ['elements'] as $c => $v) {
        foreach ($details ['elements'][$c] as $fieldname => $edetails) {

          if ($details ['type'] == 'datetime-local') {
            // Since this is datetime-local, the value is actually already in the user's timezone.
            // We want to CHANGE THIS TO UTC, so it saves in the database as UTC.
            $val_ts = @strtotime($values [$fieldname]);
            $utc_ts = convert_time($val_ts, fp_get_user_timezone(), 'UTC');
            $values [$fieldname] = date('Y-m-d H:i:s', $utc_ts);
          }

          // Do the same for "time" field type.  We need to convert to UTC from the user's timezone.
          if ($details ['type'] == 'time') {
            // Since this is time, the value is actually already in the user's timezone.
            // We want to CHANGE THIS TO UTC, so it saves in the database as UTC.
            $val_ts = @strtotime("2000-01-01 " . $values [$fieldname]); // give a bogus date just so our times make since.
            $utc_ts = convert_time($val_ts, fp_get_user_timezone(), 'UTC');
            $values [$fieldname] = date('H:i', $utc_ts);
          }


          $content->{'field__' . $fieldname}['value'] = @$values [$fieldname];
        }
      }
    }
  }

  content_save($content);
  $form_state ['content_object'] = $content;

  watchdog("content", "edited/saved cid:$cid, type:$type", array());

  if (isset($form ['#redirect'])) {
    if ($form ['#redirect']['path'] == 'content/new') {
      $form ['#redirect']['path'] = 'content/' . $content->cid;
    }
  }

  fp_add_message(t('Saved successfully.'));



}