public function processimport() { if (is_uploaded_file($_FILES['contactsfile']['tmp_name'])) { $contents = file_get_contents($_FILES['contactsfile']['tmp_name']); unlink($_FILES['contactsfile']['tmp_name']); $builder = new importcontactsarraybuilder($contents); $imports = $builder->buildarray($_POST['type']); $currentuser = lib::getitem('user'); foreach ($imports as $import) { $contact = new contact(); $adaptor = importadapter::factory($_POST['type']); $adaptor->setcontents($import); $contact->firstname = $adaptor->firstname; $contact->middlename = $adaptor->middlename; $contact->lastname = $adaptor->lastname; $contact->ownerid = $currentuser->id; $contact->save(); $possiblegroups = array('Business', 'Home'); foreach ($possiblegroups as $groupname) { $groupfinder = new contactimportgroupinterpreter($import); $group = $groupfinder->getgroup($groupname); if ($group instanceof contactgroup) { $group->contactid = $contact->id; $group->save(); $methods = new contactmethodscollection($group); $methods->generateimportmethods($import); $methods->saveall(); } } } lib::sendto(); } else { lib::seterror(array('Please upload a file.')); lib::sendto('/contacts/import'); } }
<div class="contactgrouping"> <div class="row"><label>Grouping:</label> <input name="type[<?php echo $view['counter']; ?> ][label]" value="<?php echo $view['group']->label; ?> " /></div> <div> <?php if ($view['group'] instanceof contactgroup) { $methods = new contactmethodscollection($view['group']); $methods->getwithdata(); foreach ($methods as $method) { echo view::show('contacts/method', array('method' => $method, 'counter' => $view['counter'])); } } echo view::show('contacts/method', array('method' => null, 'counter' => $view['counter'])); ?> </div> <?php if ($view['type'] == 'edit') { echo '<a href="#" class="deletecontactgrouping">Delete this group</a>'; } else { echo '<a href="#" class="addcontactgrouping">Add Another Grouping</a>'; } ?> </div>