Merge branch 'pu/2013.10-groupimport'
[tine20] / tests / tine20 / Courses / JsonTest.php
1 <?php
2 /**
3  * Tine 2.0 - http://www.tine20.org
4  * 
5  * @package     Courses
6  * @license     http://www.gnu.org/licenses/agpl.html
7  * @copyright   Copyright (c) 2009-2013 Metaways Infosystems GmbH (http://www.metaways.de)
8  * @author      Philipp Schüle <p.schuele@metaways.de>
9  */
10
11 /**
12  * Test helper
13  */
14 require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'TestHelper.php';
15
16 /**
17  * Test class for Courses_Frontend_Json
18  */
19 class Courses_JsonTest extends TestCase
20 {
21     /**
22      * @var Courses_Frontend_Json
23      */
24     protected $_json = array();
25     
26     /**
27      * config groups
28      * 
29      * @var array
30      */
31     protected $_configGroups = array();
32     
33     /**
34      * @var Tinebase_Record_RecordSet
35      */
36     protected $_groupsToDelete = null;
37     
38     /**
39      * test department
40      * 
41      * @var Tinebase_Model_Department
42      */
43     protected $_department = NULL;
44     
45     /**
46      * Student name pattern config
47      */
48     protected $_schemaConfig;
49     
50     /**
51      * The default department
52      * @var string
53      */
54     protected $_defaultDepartmentConfig;
55     
56     /**
57      * @var Boolean
58      */
59     protected $_schemaConfigChanged = FALSE;
60     
61      /**
62      * @var Boolean
63      */
64     protected $_defaultDepartmentConfigChanged = FALSE;
65     
66     /**
67      * Sets up the fixture.
68      * This method is called before a test is executed.
69      *
70      * @access protected
71      */
72     protected function setUp()
73     {
74         parent::setUp();
75         
76         $this->_json = new Courses_Frontend_Json();
77         
78         $this->_department = Tinebase_Department::getInstance()->create(new Tinebase_Model_Department(array(
79             'name'  => Tinebase_Record_Abstract::generateUID()
80         )));
81         
82         $this->_groupsToDelete = new Tinebase_Record_RecordSet('Tinebase_Model_Group');
83         foreach (array(Courses_Config::INTERNET_ACCESS_GROUP_ON, Courses_Config::INTERNET_ACCESS_GROUP_FILTERED, Courses_Config::STUDENTS_GROUP) as $configgroup) {
84             $this->_configGroups[$configgroup] = Tinebase_Group::getInstance()->create(new Tinebase_Model_Group(array(
85                 'name'   => $configgroup
86             )));
87             $this->_groupsToDelete->addRecord($this->_configGroups[$configgroup]);
88             Courses_Config::getInstance()->set($configgroup, $this->_configGroups[$configgroup]->getId());
89         }
90         
91         Courses_Config::getInstance()->set(Courses_Config::SAMBA, new Tinebase_Config_Struct(array(
92             'basehomepath' => '\\\\jo\\',
93             'homedrive' => 'X:',
94             'logonscript_postfix_teacher' => '-lehrer.cmd',
95             'logonscript_postfix_member' => '.cmd',
96             'baseprofilepath' => '\\\\jo\\profiles\\',
97         )));
98         
99         $this->_schemaConfig = Courses_Config::getInstance()->get(Courses_Config::STUDENTS_USERNAME_SCHEMA);
100         $this->_defaultDepartmentConfig = Courses_Config::getInstance()->get(Courses_Config::DEFAULT_DEPARTMENT);
101     }
102
103     /**
104      * Tears down the fixture
105      * This method is called after a test is executed.
106      *
107      * @access protected
108      */
109     protected function tearDown()
110     {
111         $this->_groupIdsToDelete = $this->_groupsToDelete->getArrayOfIds();
112         if ($this->_schemaConfigChanged) {
113             Courses_Config::getInstance()->set(Courses_Config::STUDENTS_USERNAME_SCHEMA, $this->_schemaConfig);
114         }
115         
116         if ($this->_defaultDepartmentConfigChanged) {
117             Courses_Config::getInstance()->set(Courses_Config::DEFAULT_DEPARTMENT, $this->_defaultDepartmentConfig);
118         }
119         parent::tearDown();
120     }
121     
122     /**
123      * try to add a Course
124      */
125     public function testAddCourse()
126     {
127         $course = $this->_getCourseData();
128         $courseData = $this->_json->saveCourse($course);
129         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
130         
131         // checks
132         $this->assertEquals($course['description'], $courseData['description']);
133         $this->assertEquals($course['type'], $courseData['type']['value']);
134         $this->assertEquals(Tinebase_Core::getUser()->getId(), $courseData['created_by'], 'Created by has not been set.');
135         $this->assertTrue(! empty($courseData['group_id']));
136         $this->assertGreaterThan(0, count($courseData['members']));
137         
138         // cleanup
139         $this->_json->deleteCourses($courseData['id']);
140
141         // check if it got deleted
142         $this->setExpectedException('Tinebase_Exception_NotFound');
143         Courses_Controller_Course::getInstance()->get($courseData['id']);
144     }
145     
146     /**
147      * try to get a Course
148      */
149     public function testGetCourse()
150     {
151         $course = $this->_getCourseData();
152         $courseData = $this->_json->saveCourse($course);
153         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
154         $courseData = $this->_json->getCourse($courseData['id']);
155         
156         // checks
157         $this->assertEquals($course['description'], $courseData['description']);
158         $this->assertEquals(Tinebase_Core::getUser()->getId(), $courseData['created_by']);
159         
160         // cleanup
161         $this->_json->deleteCourses($courseData['id']);
162     }
163
164     /**
165      * try to update a Course
166      */
167     public function testUpdateCourse()
168     {
169         $course = $this->_getCourseData();
170         $courseData = $this->_json->saveCourse($course);
171         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
172
173         // update Course
174         $courseData['description'] = "blubbblubb";
175         $courseData['members'] = array();
176         $courseData['type'] = $courseData['type']['value'];
177         $courseUpdated = $this->_json->saveCourse($courseData);
178         
179         // check
180         $this->assertEquals($courseData['id'], $courseUpdated['id']);
181         $this->assertEquals($courseData['description'], $courseUpdated['description']);
182         $this->assertEquals(Tinebase_Core::getUser()->getId(), $courseUpdated['last_modified_by']);
183         $this->assertEquals($courseData['members'], $courseUpdated['members']);
184         
185         // cleanup
186         $this->_json->deleteCourses($courseData['id']);
187     }
188     
189     /**
190      * try to get a Course
191      */
192     public function testSearchCourses()
193     {
194         // create
195         $course = $this->_getCourseData();
196         $courseData = $this->_json->saveCourse($course);
197         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
198         
199         // search & check
200         $search = $this->_json->searchCourses($this->_getCourseFilter($courseData['name']), $this->_getPaging());
201         $this->assertEquals($course['description'], $search['results'][0]['description']);
202         $this->assertEquals(1, $search['totalcount']);
203         
204         // cleanup
205         $this->_json->deleteCourses($courseData['id']);
206     }
207        
208     /**
209      * test for import of members (1)
210      */
211     public function testImportMembersIntoCourse1()
212     {
213         $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('admin_user_import_csv');
214         $result = $this->_importHelper(dirname(dirname(__FILE__)) . '/Admin/files/testHeadline.csv', $definition);
215
216         $this->assertEquals(4, count($result['members']), print_r($result, TRUE));
217     }
218
219     /**
220      * test for import of members (2)
221      * 
222      * @group longrunning
223      */
224     public function testImportMembersIntoCourse2()
225     {
226         $result = $this->_importHelper(dirname(__FILE__) . '/files/import.txt');
227         
228         $this->assertEquals(5, count($result['members']), print_r($result, TRUE));
229         
230         // find philipp lahm
231         $lahm = array();
232         foreach ($result['members'] as $member) {
233             if ($member['name'] == 'Lahm, Philipp') {
234                 $lahm = $member;
235             }
236         }
237         $this->assertTrue(! empty($lahm));
238         $this->assertEquals('lahmph', $lahm['data']);
239         
240         // get user and check email
241         $testConfig = Zend_Registry::get('testConfig');
242         $maildomain = ($testConfig->maildomain) ? $testConfig->maildomain : 'school.org';
243         $user = Tinebase_User::getInstance()->getFullUserById($lahm['id']);
244         $this->assertEquals('lahmph', $user->accountLoginName);
245         $this->assertEquals('lahmph@' . $maildomain, $user->accountEmailAddress);
246         $this->assertEquals('//base/school/' . $result['name'] . '/' . $user->accountLoginName, $user->accountHomeDirectory);
247     }
248     
249     /**
250      * test for import of members (3) / json import
251      */
252     public function testImportMembersIntoCourse3()
253     {
254         $result = $this->_importHelper(dirname(__FILE__) . '/files/import.txt', NULL, TRUE);
255         $this->assertEquals(5, count($result['members']), 'import failed');
256         $this->assertEquals(5, count(Tinebase_Group::getInstance()->getGroupMembers($this->_configGroups[Courses_Config::STUDENTS_GROUP])), 'imported users not added to students group');
257     }
258
259     /**
260      * test for import of members (4) / json import
261      * 
262      * @see 0006672: allow to import (csv) files with only CR linebreaks
263      * 
264      * @group longrunning
265      */
266     public function testImportMembersIntoCourse4()
267     {
268         $result = $this->_importHelper(dirname(__FILE__) . '/files/testklasse.csv', $this->_getCourseImportDefinition2(), TRUE);
269         $this->assertEquals(25, count($result['members']), 'import failed');
270         $found = FALSE;
271         foreach($result['members'] as $member) {
272             if ($member['name'] === 'Kućuk, Orkide' && $member['data'] === 'kuukor') {
273                 $found = TRUE;
274             }
275         }
276         $this->assertTrue($found, 'Member "Kućuk, Orkide" not found in result: ' . print_r($result['members'], TRUE));
277         $this->assertEquals(25, count(Tinebase_Group::getInstance()->getGroupMembers($this->_configGroups[Courses_Config::STUDENTS_GROUP])), 'imported users not added to students group');
278     }
279
280     /**
281      * test for import of members (5) / json import
282      * 
283      * @see 0006942: group memberships and login shell missing for new users
284      */
285     public function testImportMembersIntoCourse5()
286     {
287         $result = $this->_importHelper(dirname(__FILE__) . '/files/tah2a.txt', $this->_getCourseImportDefinition3('iso-8859-1'), TRUE);
288         $this->assertEquals(3, count($result['members']), 'import failed');
289         
290         // check group memberships
291         $userId = NULL;
292         foreach ($result['members'] as $result) {
293             if ($result['name'] === 'Uffbass, Umud') {
294                 $userId = $result['id'];
295             }
296         }
297         $this->assertTrue($userId !== NULL);
298         
299         $groupMemberships = Tinebase_Group::getInstance()->getGroupMemberships($userId);
300         $this->assertEquals(3, count($groupMemberships), 'new user should have 3 group memberships');
301         $this->assertTrue(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_ON]->getId(), $groupMemberships), $userId . ' not member of the internet group ' . print_r($groupMemberships, TRUE));
302         
303         $user = Tinebase_User::getInstance()->getFullUserById($userId);
304         $this->assertEquals('/bin/false', $user->accountLoginShell);
305     }
306     
307     /**
308      * testGetCoursesPreferences
309      * 
310      * @see 0006436: Courses preferences do not work (in pref panel)
311      */
312     public function testGetCoursesPreferences()
313     {
314         $tinebaseJson = new Tinebase_Frontend_Json();
315         $coursesPrefs = $tinebaseJson->searchPreferencesForApplication('Courses', array());
316         
317         $this->assertTrue($coursesPrefs['totalcount'] > 0);
318         $pref = $coursesPrefs['results'][0];
319         
320         $this->assertEquals(Tinebase_Preference_Abstract::DEFAULTPERSISTENTFILTER, $pref['name']);
321         $this->assertGreaterThanOrEqual(2, count($pref['options']));
322     }
323
324     /**
325      * testImportWithMissingList
326      * 
327      * @see 0007460: check existence of group/list before user import
328      */
329     public function testImportWithMissingList()
330     {
331         $result = $this->_importHelper(dirname(__FILE__) . '/files/tah2a.txt', $this->_getCourseImportDefinition3('iso-8859-1'), TRUE, TRUE);
332         $this->assertEquals(3, count($result['members']), 'import failed');
333     }
334     
335     /**
336      * test internet access on/off/filtered
337      * 
338      * @todo remove some code duplication
339      */
340     public function testInternetAccess()
341     {
342         // create new course with internet access
343         $course = $this->_getCourseData();
344         $courseData = $this->_json->saveCourse($course);
345         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
346         $userId = $courseData['members'][0]['id'];
347         $groupMemberships = Tinebase_Group::getInstance()->getGroupMemberships($userId);
348         $this->assertTrue(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_ON]->getId(), $groupMemberships), $userId . ' not member of the internet group ' . print_r($groupMemberships, TRUE));
349         
350         // filtered internet access
351         $courseData['internet'] = 'FILTERED';
352         $courseData['type'] = $courseData['type']['value'];
353         $courseData = $this->_json->saveCourse($courseData);
354         $groupMemberships = Tinebase_Group::getInstance()->getGroupMemberships($userId);
355         $this->assertTrue(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_FILTERED]->getId(), $groupMemberships), 'not member of the filtered internet group ' . print_r($groupMemberships, TRUE));
356         $this->assertFalse(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_ON]->getId(), $groupMemberships), 'member of the internet group ' . print_r($groupMemberships, TRUE));
357         
358         // remove internet access
359         $courseData['internet'] = 'OFF';
360         $courseData['type'] = $courseData['type']['value'];
361         $courseData = $this->_json->saveCourse($courseData);
362         $groupMemberships = Tinebase_Group::getInstance()->getGroupMemberships($userId);
363         $this->assertFalse(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_ON]->getId(), $groupMemberships), 'member of the internet group ' . print_r($groupMemberships, TRUE));
364         $this->assertFalse(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_FILTERED]->getId(), $groupMemberships), 'member of the filtered internet group ' . print_r($groupMemberships, TRUE));
365     }
366     
367     /**
368      * testAddNewMember
369      * 
370      * @see 0006372: add new course member with a button
371      * @see 0006878: set primary group for manually added users
372      */
373     public function testAddNewMember()
374     {
375         $course = $this->_getCourseData();
376         $courseData = $this->_json->saveCourse($course);
377         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
378         
379         $result = $this->_json->addNewMember(array(
380             'accountFirstName' => 'jams',
381             'accountLastName'  => 'hot',
382         ), $courseData);
383         
384         $this->assertEquals(2, count($result['results']));
385         
386         $id = NULL;
387         foreach ($result['results'] as $result) {
388             if ($result['name'] === 'hot, jams') {
389                 $id = $result['id'];
390             }
391         }
392         $this->assertTrue($id !== NULL);
393         
394         $newUser = Tinebase_User::getInstance()->getFullUserById($id);
395         $this->assertEquals('hotja', $newUser->accountLoginName);
396         $this->assertEquals('/bin/false', $newUser->accountLoginShell);
397         
398         $newUserMemberships = Tinebase_Group::getInstance()->getGroupMemberships($newUser);
399         
400         $this->assertEquals(4, count($newUserMemberships), 'new user should have 4 group memberships');
401         $this->assertTrue(in_array(Tinebase_Group::getInstance()->getDefaultGroup()->getId(), $newUserMemberships),
402             'could not find default group in memberships: ' . print_r($newUserMemberships, TRUE));
403         $this->assertTrue(in_array($this->_configGroups[Courses_Config::INTERNET_ACCESS_GROUP_ON]->getId(), $newUserMemberships),
404             $id . ' not member of the internet group ' . print_r($newUserMemberships, TRUE));
405         $this->assertTrue(in_array($this->_configGroups[Courses_Config::STUDENTS_GROUP]->getId(), $newUserMemberships),
406             $id . ' not member of the students group ' . print_r($newUserMemberships, TRUE));
407     }
408     
409     /**
410      * testApplySambaSettings
411      * 
412      * @see 0006910: new manual users have no samba settings
413      */
414     public function testApplySambaSettings()
415     {
416         $user = Tinebase_Core::getUser();
417         $config = Courses_Config::getInstance()->samba;
418         $profilePath = $config->baseprofilepath . 'school' . '\\' . 'coursexy' . '\\';
419         $user->applyOptionsAndGeneratePassword(array('samba' => array(
420             'homePath'      => $config->basehomepath,
421             'homeDrive'     => $config->homedrive,
422             'logonScript'   => 'coursexy' . $config->logonscript_postfix_member,
423             'profilePath'   => $profilePath,
424             'pwdCanChange'  => new Tinebase_DateTime('@1'),
425             'pwdMustChange' => new Tinebase_DateTime('@1')
426         )));
427
428         // check samba settings
429         $this->assertEquals($profilePath . $user->accountLoginName, $user->sambaSAM->profilePath);
430     }
431     
432     /**
433      * testTeacherDefaultFavorite
434      * 
435      * @see 0006876: create "my course" default favorite for new teachers
436      */
437     public function testTeacherDefaultFavorite()
438     {
439         $course = $this->_getCourseData();
440         $courseData = $this->_json->saveCourse($course);
441         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
442         $teacher = Tinebase_User::getInstance()->getFullUserById($courseData['members'][0]['id']);
443         
444         $filter = Tinebase_PersistentFilter::getInstance()->getFilterById(
445             Tinebase_Core::getPreference('Courses')->getValueForUser(Courses_Preference::DEFAULTPERSISTENTFILTER, $teacher->getId())
446         );
447         $this->assertEquals(array(array('field' => 'name', 'operator' => 'equals', 'value' => $course['name'])), $filter->toArray());
448     }
449     
450     /**
451      * Test students loginname with schema 3
452      */
453     public function testStudentNameSchema3()
454     {
455         $this->_schemaConfigChanged = true;
456         Courses_Config::getInstance()->set(Courses_Config::STUDENTS_USERNAME_SCHEMA, 3);
457         
458         $course = $this->_getCourseData();
459         $courseData = $this->_json->saveCourse($course);
460         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
461         
462         $result = $this->_json->addNewMember(array(
463             'accountFirstName' => 'jams',
464             'accountLastName'  => 'hot',
465         ), $courseData);
466         
467         $this->assertEquals(2, count($result['results']));
468         
469         $id = NULL;
470         foreach ($result['results'] as $result) {
471             if ($result['name'] === 'hot, jams') {
472                 $id = $result['id'];
473             }
474         }
475         $this->assertTrue($id !== NULL);
476         
477         $newUser = Tinebase_User::getInstance()->getFullUserById($id);
478         $this->assertEquals('j.hot', $newUser->accountLoginName);
479     }
480     
481     /**
482      * Test if the default department is returned
483      */
484     public function testDefaultDepartment()
485     {
486         $this->_defaultDepartmentConfigChanged = true;
487         Courses_Config::getInstance()->set(Courses_Config::DEFAULT_DEPARTMENT, $this->_department->name);
488         $result = $this->_json->getRegistryData();
489         $this->assertEquals($this->_department->id, $result['defaultType']['value']);
490     }
491     
492     /************ protected helper funcs *************/
493     
494     /**
495      * get Course
496      *
497      * @return array
498      */
499     protected function _getCourseData()
500     {
501         return array(
502             'name'          => Tinebase_Record_Abstract::generateUID(),
503             'description'   => 'blabla',
504             'type'          => $this->_department->getId(),
505             'internet'      => 'ON',
506         );
507     }
508         
509     /**
510      * get paging
511      *
512      * @return array
513      */
514     protected function _getPaging()
515     {
516         return array(
517             'start' => 0,
518             'limit' => 50,
519             'sort' => 'creation_time',
520             'dir' => 'ASC',
521         );
522     }
523
524     /**
525      * get Course filter
526      *
527      * @return array
528      */
529     protected function _getCourseFilter($_courseName)
530     {
531         return array(
532             array(
533                 'field' => 'name', 
534                 'operator' => 'contains', 
535                 'value' => $_courseName
536             ),
537         );
538     }
539     
540     /**
541      * import file
542      * 
543      * @param string $_filename
544      * @param Tinebase_Model_ImportExportDefinition $_definition
545      * @param boolean $_useJsonImportFn
546      * @param boolean $removeGroupList
547      * @return array course data
548      */
549     protected function _importHelper($_filename, Tinebase_Model_ImportExportDefinition $_definition = NULL, $_useJsonImportFn = FALSE, $removeGroupList = FALSE)
550     {
551         $definition = ($_definition !== NULL) ? $_definition : $this->_getCourseImportDefinition();
552         
553         $course = $this->_getCourseData();
554         $courseData = $this->_json->saveCourse($course);
555         $this->_groupsToDelete->addRecord(Tinebase_Group::getInstance()->getGroupById($courseData['group_id']));
556         
557         if ($removeGroupList) {
558             $group = Admin_Controller_Group::getInstance()->get($courseData['group_id']);
559             Addressbook_Controller_List::getInstance()->delete($group->list_id);
560         }
561         
562         if ($_useJsonImportFn) {
563             $tempFileBackend = new Tinebase_TempFile();
564             $tempFile = $tempFileBackend->createTempFile($_filename);
565             Courses_Config::getInstance()->set(Courses_Config::STUDENTS_IMPORT_DEFINITION, $definition->name);
566             $result = $this->_json->importMembers($tempFile->getId(), $courseData['group_id'], $courseData['id']);
567             
568             $this->assertGreaterThan(0, $result['results']);
569             
570         } else {
571             $testConfig = Zend_Registry::get('testConfig');
572             $maildomain = ($testConfig->maildomain) ? $testConfig->maildomain : 'school.org';
573             
574             $importer = call_user_func($definition->plugin . '::createFromDefinition', $definition, array(
575                     'group_id'                  => $courseData['group_id'],
576                     'accountHomeDirectoryPrefix' => '//base/school/' . $courseData['name'] . '/',
577                     'accountEmailDomain'        => $maildomain,
578                     'password'                  => $courseData['name'],
579                     'samba'                     => array(
580                         'homePath'    => '//basehome/',
581                         'homeDrive'   => 'H:',
582                         'logonScript' => 'logon.bat',
583                         'profilePath' => '\\\\profile\\',
584                     )
585                 )
586             );
587             $tempFilename = TestServer::replaceEmailDomainInFile($_filename);
588             $importer->importFile($tempFilename);
589         }
590         $courseData = $this->_json->getCourse($courseData['id']);
591
592         return $courseData;
593     }
594     
595     /**
596      * returns course import definition
597      * 
598      * @return Tinebase_Model_ImportExportDefinition
599      */
600     protected function _getCourseImportDefinition()
601     {
602         try {
603             $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('course_user_import_csv');
604         } catch (Tinebase_Exception_NotFound $e) {
605             $definition = Tinebase_ImportExportDefinition::getInstance()->create(new Tinebase_Model_ImportExportDefinition(array(
606                     'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Admin')->getId(),
607                     'name'              => 'course_user_import_csv',
608                     'type'              => 'import',
609                     'model'             => 'Tinebase_Model_FullUser',
610                     'plugin'            => 'Admin_Import_User_Csv',
611                     'plugin_options'    => '<?xml version="1.0" encoding="UTF-8"?>
612             <config>
613                 <headline>1</headline>
614                 <use_headline>0</use_headline>
615                 <dryrun>0</dryrun>
616                 <encoding>UTF-8</encoding>
617                 <delimiter>;</delimiter>
618                 <mapping>
619                     <field>
620                         <source>lastname</source>
621                         <destination>accountLastName</destination>
622                     </field>
623                     <field>
624                         <source>firstname</source>
625                         <destination>accountFirstName</destination>
626                     </field>
627                 </mapping>
628             </config>')
629             ));
630         }
631         
632         return $definition;
633     }
634     
635      /**
636      * returns course import definition
637      * 
638      * @return Tinebase_Model_ImportExportDefinition
639      */
640     protected function _getCourseImportDefinition2()
641     {
642         try {
643             $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('course_user_import_csv2');
644         } catch (Tinebase_Exception_NotFound $e) {
645             $definition = Tinebase_ImportExportDefinition::getInstance()->create(new Tinebase_Model_ImportExportDefinition(array(
646                     'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Admin')->getId(),
647                     'name'              => 'course_user_import_csv2',
648                     'type'              => 'import',
649                     'model'             => 'Tinebase_Model_FullUser',
650                     'plugin'            => 'Admin_Import_User_Csv',
651                     'plugin_options'    => '<?xml version="1.0" encoding="UTF-8"?>
652             <config>
653                 <headline>1</headline>
654                 <use_headline>0</use_headline>
655                 <dryrun>0</dryrun>
656                 <encoding>MAC-CENTRALEUROPE</encoding>
657                 <delimiter>;</delimiter>
658                 <mapping>
659                     <field>
660                         <source>VORNAME</source>
661                         <destination>accountFirstName</destination>
662                     </field>
663                     <field>
664                         <source>NAME</source>
665                         <destination>accountLastName</destination>
666                     </field>
667                     </mapping>
668             </config>')
669             ));
670         }
671         
672         return $definition;
673     }
674     
675     /**
676      * returns course import definition
677      * 
678      * @param string $encoding
679      * @return Tinebase_Model_ImportExportDefinition
680      */
681     protected function _getCourseImportDefinition3($encoding = 'UTF-8')
682     {
683         try {
684             $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('course_user_import_csv');
685         } catch (Tinebase_Exception_NotFound $e) {
686             $definition = Tinebase_ImportExportDefinition::getInstance()->create(new Tinebase_Model_ImportExportDefinition(array(
687                     'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('Admin')->getId(),
688                     'name'              => 'course_user_import_csv',
689                     'type'              => 'import',
690                     'model'             => 'Tinebase_Model_FullUser',
691                     'plugin'            => 'Admin_Import_User_Csv',
692                     'plugin_options'    => '<?xml version="1.0" encoding="UTF-8"?>
693             <config>
694                 <headline>1</headline>
695                 <use_headline>0</use_headline>
696                 <dryrun>0</dryrun>
697                 <encoding>' . $encoding . '</encoding>
698                 <delimiter>;</delimiter>
699                 <mapping>
700                     <field>
701                         <source>Name</source>
702                         <destination>accountLastName</destination>
703                     </field>
704                     <field>
705                         <source>Vorname</source>
706                         <destination>accountFirstName</destination>
707                     </field>
708                 </mapping>
709             </config>')
710             ));
711         }
712         
713         
714         return $definition;
715     }
716 }