[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [7303] added possibility to choose file when importin
From: |
Erik Holm-Larsen |
Subject: |
[Fmsystem-commits] [7303] added possibility to choose file when importing activities |
Date: |
Thu, 26 May 2011 06:01:42 +0000 |
Revision: 7303
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7303
Author: erikhl
Date: 2011-05-26 06:01:42 +0000 (Thu, 26 May 2011)
Log Message:
-----------
added possibility to choose file when importing activities
fixed import method (added contact persons, description, etc)
Modified Paths:
--------------
trunk/activitycalendar/inc/class.soactivity.inc.php
trunk/activitycalendar/inc/class.uiimport.inc.php
trunk/activitycalendar/templates/base/activity_import.php
Modified: trunk/activitycalendar/inc/class.soactivity.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.soactivity.inc.php 2011-05-25 21:17:45 UTC
(rev 7302)
+++ trunk/activitycalendar/inc/class.soactivity.inc.php 2011-05-26 06:01:42 UTC
(rev 7303)
@@ -251,7 +251,55 @@
return isset($result);
}
+
+ function import_activity($activity)
+ {
+ $id = intval($activity->get_id());
+ $ts_now = strtotime('now');
+
+ $columns = array(
+ 'title',
+ 'organization_id',
+ 'group_id',
+ 'district',
+ 'office',
+ 'category',
+ 'state',
+ 'target',
+ 'description',
+ 'arena',
+ 'time',
+ 'last_change_date',
+ 'create_date',
+ 'contact_person_1',
+ 'contact_person_2',
+ 'special_adaptation'
+ );
+
+ $values = array(
+ $this->marshal($activity->get_title(), 'string'),
+ $this->marshal($activity->get_organization_id(), 'int'),
+ $this->marshal($activity->get_group_id(), 'int'),
+ $this->marshal($activity->get_district(), 'string'),
+ $this->marshal($activity->get_office(), 'int'),
+ $this->marshal($activity->get_category(), 'int'),
+ $this->marshal($activity->get_state(), 'int'),
+ $this->marshal($activity->get_target(), 'string'),
+ $this->marshal($activity->get_description(), 'string'),
+ $this->marshal($activity->get_arena(), 'int'),
+ $this->marshal($activity->get_time(), 'string'),
+ $this->marshal($activity->get_last_change_date(),
'int'),
+ $this->marshal($ts_now, 'int'),
+ $this->marshal($activity->get_contact_person_1(),
'int'),
+ $this->marshal($activity->get_contact_person_2(),
'int'),
+ ($activity->get_special_adaptation() ? "true" : "false")
+ );
+
+ $result = $this->db->query('INSERT INTO activity_activity (' .
join(',', $columns) . ') VALUES (' . join(',', $values) . ')',
__LINE__,__FILE__);
+ return isset($result);
+ }
+
public function get_id_field_name($extended_info = false)
{
if(!$extended_info)
@@ -458,6 +506,26 @@
return $result;
}
+ function update_org_description($org_id, $description)
+ {
+ if($org_id != null)
+ {
+ $sql = "update bb_organization set
description='{$description}' where id={$org_id}";
+ $result = $this->db->query($sql, __LINE__, __FILE__);
+ }
+ return isset($result);
+ }
+
+ function set_org_active($org_id)
+ {
+ if($org_id != null)
+ {
+ $sql = "update bb_organization set show_in_portal=1
where id={$org_id}";
+ $result = $this->db->query($sql, __LINE__, __FILE__);
+ }
+ return isset($result);
+ }
+
function get_activities()
{
$sql = "SELECT * FROM activity_activity";
Modified: trunk/activitycalendar/inc/class.uiimport.inc.php
===================================================================
--- trunk/activitycalendar/inc/class.uiimport.inc.php 2011-05-25 21:17:45 UTC
(rev 7302)
+++ trunk/activitycalendar/inc/class.uiimport.inc.php 2011-05-26 06:01:42 UTC
(rev 7303)
@@ -2,6 +2,7 @@
phpgw::import_class('activitycalendar.uicommon');
phpgw::import_class('activitycalendar.soarena');
phpgw::import_class('activitycalendar.soactivity');
+ phpgw::import_class('activitycalendar.soorganization');
include_class('activitycalendar', 'arena', 'inc/model/');
include_class('activitycalendar', 'activity', 'inc/model/');
@@ -17,8 +18,9 @@
protected $errors;
// File system path to import folder on server
- protected $path;
+ protected $file;
protected $district;
+ protected $csvdata;
// Label on the import button. Changes as we step through the
import process.
protected $import_button_label;
@@ -66,7 +68,13 @@
// Get the path for user input or use a default
path
$this->path = phpgw::get_var("import_path") ?
phpgw::get_var("import_path") : '/home/notroot/FacilitExport';
$this->office = phpgw::get_var("district") ?
phpgw::get_var("district") : '1';
- phpgwapi_cache::session_set('activitycalendar',
'import_path', $this->path);
+ $this->file = $_FILES['file']['tmp_name'];
+ $this->csvdata =
$this->getcsvdata($_FILES['file']['tmp_name']);
+ //var_dump($this->office);
+ //var_dump($_FILES['file']['name']);
+ //var_dump($_FILES['file']['tmp_name']);
+ phpgwapi_cache::session_set('activitycalendar',
'file', $this->file);
+ phpgwapi_cache::session_set('activitycalendar',
'csvdata', $this->csvdata);
phpgwapi_cache::session_set('activitycalendar',
'import_district', $this->office);
$GLOBALS['phpgw']->redirect_link('/index.php',
array('menuaction' => 'activitycalendar.uiimport.index', 'importstep' =>
'true'));
}
@@ -76,7 +84,8 @@
$start = date("G:i:s",$start_time);
echo "<h3>Import started at: {$start}</h3>";
echo "<ul>";
- $this->path =
phpgwapi_cache::session_get('activitycalendar', 'import_path') . '/aktiviteter';
+ $this->file =
phpgwapi_cache::session_get('activitycalendar', 'file');
+ $this->csvdata =
phpgwapi_cache::session_get('activitycalendar', 'csvdata');
$this->office =
phpgwapi_cache::session_get('activitycalendar', 'import_district');
//$this->path =
'/home/notroot/FacilitExport/aktiviteter';
@@ -182,19 +191,17 @@
$soarena = activitycalendar_soarena::get_instance();
$soactivity =
activitycalendar_soactivity::get_instance();
- $datalines = $this->getcsvdata($this->path .
"/import_all.csv");
+ //var_dump($_FILES['file']['name']);
+ //var_dump($this->file);
+ //$datalines =
$this->getcsvdata($_FILES['file']['tmp_name']);;
+ $datalines = $this->csvdata;
+ //$datalines = $this->getcsvdata($this->file);
//$activity_district = $this->district;
- //var_dump($this->district);
$this->messages[] = "Read 'import_all.csv' file in " .
(time() - $start_time) . " seconds";
$this->messages[] = "'importfile.csv' contained " .
count($datalines) . " lines";
- foreach ($datalines as $data) {
-/* if(count($data) <= 8)
- {
- continue;
- }
-*/
+ foreach ($datalines as $data) {
$arena = new activitycalendar_arena();
//8: sted, 9:adresse
$arena_name = $this->decode($data[7]);
@@ -240,6 +247,7 @@
//$activity_description = substr($activity_description,0,254);
//}
}
+ $activity_persons =
activitycalendar_soorganization::get_instance()->get_contacts($activity_org);
}
}
$activity_adapted = $this->decode($data[3]);
@@ -272,6 +280,7 @@
$m = $act_update_array[1];
$d = $act_update_array[0];
$activity_updated_date =
strtotime($y."-".$m."-".$d);
+
//var_dump($activity_updated_date);
}
}
$activity_district = $this->decode($data[21]);
@@ -295,9 +304,14 @@
$activity->set_office($this->office);
$activity->set_district($activity_district);
$activity->set_last_change_date($activity_updated_date);
+ if($activity_persons)
+ {
+ //set contact persons
+
$activity->set_contact_persons($activity_persons);
+ }
//var_dump($activity);
// All is good, store activity
- if ($soactivity->store($activity)) {
+ if
($soactivity->import_activity($activity)) {
$this->messages[] =
"Successfully imported activity: Title ({$this->decode($data[1])})";
} else {
$this->errors[] = "Error
importing activity: Title ({$this->decode($data[1])})";
@@ -378,8 +392,8 @@
* Do end-of-import clean up
*/
protected function clean_up() {
- $socontract = rental_socontract::get_instance();
- $socontract->clear_last_edited_table();
+ //$socontract = rental_socontract::get_instance();
+ //$socontract->clear_last_edited_table();
}
private function log_messages($step) {
Modified: trunk/activitycalendar/templates/base/activity_import.php
===================================================================
--- trunk/activitycalendar/templates/base/activity_import.php 2011-05-25
21:17:45 UTC (rev 7302)
+++ trunk/activitycalendar/templates/base/activity_import.php 2011-05-26
06:01:42 UTC (rev 7303)
@@ -11,9 +11,9 @@
<div id="messageHolder"></div>
-<form action="index.php?menuaction=activitycalendar.uiimport.index"
method="post">
+<form action="index.php?menuaction=activitycalendar.uiimport.index"
method="post" enctype="multipart/form-data">
<fieldset>
- <label for="path">Path to activities file:</label> <input
type="text" name="import_path" id="import_path" value="<?php echo $import_path
?>" size="60"/>
+ <label for="file">Choose activities file:</label> <input
type="file" name="file" id="file" />
<label for="district">Location for the imported
activities:</label>
<select name="district" id="district">
<?php
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [7303] added possibility to choose file when importing activities,
Erik Holm-Larsen <=