/** * Get time() for the beginning and end of a giving month within a giving year. * * @uses date( 't' ) to get the number of days in the giving month and year * * @param mixed $month * @param mixed $year * @param mixed $return * @param mixed $format */ public function months_time_range($month, $year, $return = 'array', $format = 'time') { $array = array(); // create a date range that spans a month whatever the months total days $array['start'] = mktime(0, 0, 0, $month, 1, $year); if ($format == 'date') { $array['start'] = CSV2POST::datewp(0, $array['start']); } // t = number of days in giving month - set timestamp only to point to correct month "1" does not matter $array['end'] = $end_time = mktime(23, 59, 59, $month, date('t', strtotime($month . '/1/' . $year)), $year); if ($format == 'date') { $array['end'] = CSV2POST::datewp(0, $array['end']); } if ($return == 'start') { return $array['start']; } elseif ($return == 'end') { return $array['end']; } else { return $array; } }
/** * form processing function * * @author Ryan Bayne * @package CSV 2 POST * @since 8.0.0 * @version 1.1 */ public function newprojectusingexistingsource() { $sourceid_array = array(); // increment string key: source1,source2,source3 (not sure why I done this but stick with it for now) // set project name - default to the date if user did not enter a name if (empty($_POST['newprojectname'])) { $project_name = CSV2POST::datewp(); } else { $project_name = sanitize_text_field($_POST['newprojectname']); } if (!isset($_POST['newprojectdatasource']) || !is_numeric($_POST['newprojectdatasource'])) { $this->UI->create_notice(__('The source ID submitted is invalid and your request to create a new project was denied.'), 'error', 'Small', __('Invalid Source ID')); return false; } $sourceid_array['source1'] = $_POST['newprojectdatasource']; // create a new project in the c2pprojects table $projectid = $this->CSV2POST->insert_project($project_name, $sourceid_array); // ensure we have valid $projectid and set it as the current project if (!is_numeric($projectid)) { $this->UI->create_notice(__('The plugin could not finish inserting your new project to the database. This should never happen, please report it.'), 'error', 'Small', __('Problem Detected When Creating Project')); return false; } // if applicable we apply defaults to the projects settings array, initialize it with coded settings or users own defaults if (isset($_POST['applydefaults']) && $_POST['applydefaults'] == 'enabled') { $this->CSV2POST->apply_project_defaults($projectid); } // from here on we can begin using the $project_array $project_array = $this->CSV2POST->get_project($projectid); $project_settings_array = maybe_unserialize($project_array->projectsettings); // add the id column to the project settings array // this helps to avoid calling entire source record in some situations when querying imported data // get the source data $source_array = $this->CSV2POST->get_source($sourceid_array['source1']); $project_settings_array['idcolumn'] = $source_array->idcolumn; $this->CSV2POST->update_project($projectid, array('projectsettings' => maybe_serialize($project_settings_array)), false); // set the current project global $csv2post_settings; $csv2post_settings['currentproject'] = $projectid; $this->CSV2POST->update_settings($csv2post_settings); // update source rows with project id // this is not required, I intend for multiple projects to use a single source, but in a simple setup // where the user isnt doing anything advanced, this measure may help $this->CSV2POST->update_sources_withprojects($projectid, $sourceid_array); $this->UI->create_notice('Your project has been created and the ID is ' . $projectid . '. The default project name is ' . $project_name . ' which you can change using project settings.', 'success', 'Small', __('Project Created')); // log $atts = array('outcome' => 1, 'line' => __LINE__, 'function' => __FUNCTION__, 'file' => __FILE__, 'userid' => get_current_user_id(), 'type' => 'general', 'category' => 'projectchange', 'action' => sprintf(__('New project created with ID %s.', 'csv2post'), $projectid), 'priority' => 'normal', 'triga' => 'manualrequest'); $this->CSV2POST->newlog($atts); }