Exemplo n.º 1
0
function import_csv($csv)
{
    $error_mess = array();
    $update = 0;
    $create = 0;
    $error = 0;
    while ($tab = $csv->readLine()) {
        $parentOk = false;
        if ($tab['Parent'] !== NULL) {
            $parent = \Pasteque\providersService::getByName($tab['Parent']);
            $image = NULL;
            if ($parent) {
                $parentOk = true;
                $tab['Parent'] = $parent->id;
            }
        } else {
            // provider isn't subprovider
            $parentOk = true;
        }
        if ($parentOk) {
            $prov = new \Pasteque\provider($tab['Parent'], $tab['Designation'], $image, $tab['Ordre']);
            $provider_exist = \Pasteque\providersService::getByName($prov->label);
            //UPDATE provider
            if ($provider_exist) {
                $prov->id = $provider_exist->id;
                if (\Pasteque\providersService::updateprov($prov)) {
                    $update++;
                } else {
                    $error++;
                    $error_mess[] = \i18n("On line %d: Cannot update provider: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['Designation']);
                }
                //CREATE provider
            } else {
                $id = \Pasteque\providersService::createprov($prov);
                if ($id) {
                    $create++;
                } else {
                    $error++;
                    $error_mess[] = \i18n("On line %d: Cannot create provider: '%s'", PLUGIN_NAME, $csv->getCurrentLineNumber(), $tab['Designation']);
                }
            }
        } else {
            $error++;
            $error_mess[] = \i18n("On line %d: provider parent doesn't exist", PLUGIN_NAME, $csv->getCurrentLineNumber());
        }
    }
    $message = \i18n("%d line(s) inserted, %d line(s) modified, %d error(s)", PLUGIN_NAME, $create, $update, $error);
    $csv->close();
    \Pasteque\tpl_msg_box($message, $error_mess);
}
Exemplo n.º 2
0
        $dispOrder = 0;
        if ($_POST['dispOrder'] !== "") {
            $dispOrder = intval($_POST['dispOrder']);
        }
        $prov = new \Pasteque\Provider($_POST['label'], $img !== null, $_POST['firstName'], $_POST['lastName'], $_POST['email'], $_POST['phone1'], $_POST['phone2'], $_POST['website'], $_POST['fax'], $_POST['addr1'], $_POST['addr2'], $_POST['zipCode'], $_POST['city'], $_POST['region'], $_POST['country'], $_POST['notes'], $_POST['visible'], $dispOrder);
        $id = \Pasteque\providersService::createprov($prov, $img);
        if ($id !== FALSE) {
            $message = \i18n("provider saved. <a href=\"%s\">Go to the provider page</a>.", PLUGIN_NAME, \Pasteque\get_module_url_action(PLUGIN_NAME, 'provider_edit', array('id' => $id)));
        } else {
            $error = \i18n("Unable to save changes");
        }
    }
}
$provider = NULL;
if (isset($_GET['id'])) {
    $provider = \Pasteque\providersService::get($_GET['id']);
}
?>
<h1><?php 
\pi18n("Edit a provider", PLUGIN_NAME);
?>
</h1>

<?php 
\Pasteque\tpl_msg_box($message, $error);
?>

<form class="edit" action="<?php 
echo \Pasteque\get_current_url();
?>
" method="post" enctype="multipart/form-data">
Exemplo n.º 3
0
//    You should have received a copy of the GNU General Public License
//    along with Pastèque.  If not, see <http://www.gnu.org/licenses/>.
// providers action
namespace ProductProviders;

$message = NULL;
$error = NULL;
if (isset($_POST['delete-prov'])) {
    if (\Pasteque\providersService::deleteprov($_POST['delete-prov'])) {
        $message = \i18n("Changes saved");
    } else {
        $error = \i18n("Unable to save changes");
        $error .= " " . \i18n("Only empty provider can be deleted", PLUGIN_NAME);
    }
}
$providers = \Pasteque\providersService::getAll();
?>
<h1><?php 
\pi18n("Providers", PLUGIN_NAME);
?>
</h1>

<?php 
\Pasteque\tpl_msg_box($message, $error);
?>

<?php 
\Pasteque\tpl_btn('btn', \Pasteque\get_module_url_action(PLUGIN_NAME, "provider_edit"), \i18n('Add a provider', PLUGIN_NAME), 'img/btn_add.png');
\Pasteque\tpl_btn('btn', \Pasteque\get_module_url_action(PLUGIN_NAME, "providersManagement"), \i18n('Import providers', PLUGIN_NAME), 'img/btn_add.png');
?>